X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-scr.c;h=9a3f3dfc77d0dd1b45dfdbdfff40256ba0e36899;hp=3966e956aac504037663a6a046a6859282ea0f88;hb=47bc66a0c744f68a84147b0bd616ab25a242fb70;hpb=863c609797ca6d556dd3a4586fc07a6f4a5472d4 diff --git a/ui/ncurses/nc-scr.c b/ui/ncurses/nc-scr.c index 3966e95..9a3f3df 100644 --- a/ui/ncurses/nc-scr.c +++ b/ui/ncurses/nc-scr.c @@ -16,8 +16,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" + +#define _GNU_SOURCE + #include #include +#include #include "log/log.h" #include "talloc/talloc.h" @@ -34,6 +39,14 @@ void nc_start(void) intrflush(stdscr, FALSE); /* Disable interrupt flush. */ curs_set(0); /* Make cursor invisible */ nodelay(stdscr, TRUE); /* Enable non-blocking getch() */ + + /* We may be operating with an incorrect $TERM type; in this case + * the keymappings will be slightly broken. We want at least + * backspace to work though, so we'll define both DEL and ^H to + * map to backspace */ + define_key("\x7f", KEY_BACKSPACE); + define_key("\x08", KEY_BACKSPACE); + while (getch() != ERR) /* flush stdin */ (void)0; } @@ -58,11 +71,23 @@ static void nc_scr_status_draw(struct nc_scr *scr) void nc_scr_frame_draw(struct nc_scr *scr) { - DBGS("title '%s'\n", scr->frame.title); + int ltitle_len, rtitle_len; + + DBGS("ltitle '%s'\n", scr->frame.ltitle); + DBGS("rtitle '%s'\n", scr->frame.rtitle); DBGS("help '%s'\n", scr->frame.help); DBGS("status '%s'\n", scr->frame.status); - mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.title); + ltitle_len = strlen(scr->frame.ltitle); + rtitle_len = scr->frame.rtitle ? strlen(scr->frame.rtitle) : 0; + + /* if both ltitle and rtitle don't fit, trim rtitle */ + if (ltitle_len + rtitle_len + nc_scr_pos_lrtitle_space > COLS - 2) + rtitle_len = COLS - 2 - ltitle_len - nc_scr_pos_lrtitle_space; + + mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.ltitle); + mvwaddnstr(scr->main_ncw, nc_scr_pos_title, COLS - rtitle_len - 1, + scr->frame.rtitle, rtitle_len); mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2); mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE, @@ -102,7 +127,7 @@ void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...) int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x, void *ui_ctx, - void (*process_key)(struct nc_scr *), + void (*process_key)(struct nc_scr *, int), int (*post)(struct nc_scr *), int (*unpost)(struct nc_scr *), void (*resize)(struct nc_scr *))