X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-scr.c;h=a02627bae946b761b78484c40fd306022aaed63d;hp=062d34a7b177d835b1b81e5befc5b2fa95a37249;hb=70907c3fc4b344d00ce900e6a536e9cc16a35216;hpb=a610837ff38f5cc80bcbad465a80ab920e67927d diff --git a/ui/ncurses/nc-scr.c b/ui/ncurses/nc-scr.c index 062d34a..a02627b 100644 --- a/ui/ncurses/nc-scr.c +++ b/ui/ncurses/nc-scr.c @@ -16,53 +16,63 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif + #include #include +#include #include "log/log.h" #include "talloc/talloc.h" #include "nc-scr.h" -void nc_start(void) +static void nc_scr_status_clear(struct nc_scr *scr) { - initscr(); /* Initialize ncurses. */ - cbreak(); /* Disable line buffering. */ - noecho(); /* Disable getch() echo. */ - keypad(stdscr, TRUE); /* Enable num keypad keys. */ - nonl(); /* Disable new-line translation. */ - intrflush(stdscr, FALSE); /* Disable interrupt flush. */ - curs_set(0); /* Make cursor invisible */ - nodelay(stdscr, TRUE); /* Enable non-blocking getch() */ - while (getch() != ERR) /* flush stdin */ - (void)0; + mvwhline(scr->main_ncw, LINES - nc_scr_pos_status, 0, ' ', COLS); } -void nc_atexit(void) +static void nc_scr_status_draw(struct nc_scr *scr) { - clear(); - refresh(); - endwin(); + mvwaddnstr(scr->main_ncw, LINES - nc_scr_pos_status, 1, + scr->frame.status, COLS); } -static void nc_scr_status_clear(struct nc_scr *scr) +int nc_scr_post(struct nc_scr *scr) { - mvwhline(scr->main_ncw, LINES - nc_scr_pos_status, 0, ' ', COLS); + if (scr->post) + return scr->post(scr); + return 0; } -static void nc_scr_status_draw(struct nc_scr *scr) +int nc_scr_unpost(struct nc_scr *scr) { - mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_status, 1, - scr->frame.status); + if (scr->unpost) + return scr->unpost(scr); + return 0; } 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, @@ -118,7 +128,7 @@ int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x, scr->sub_ncw = derwin(scr->main_ncw, LINES - nc_scr_frame_lines, - COLS - 1 - begin_x, + COLS - nc_scr_frame_cols - begin_x, nc_scr_pos_sub, begin_x);