From ea261b8852a7c1dad462e71ed0442c00a142adc2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 20 Apr 2012 01:24:24 +0100 Subject: Refactored title bar status --- title_bar.c | 61 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/title_bar.c b/title_bar.c index f6db121e..96d8bc5d 100644 --- a/title_bar.c +++ b/title_bar.c @@ -27,8 +27,12 @@ static WINDOW *title_bar; static char *current_title = NULL; +static int connected = FALSE; static int dirty; +void _title_bar_draw_title(void); +void _title_bar_draw_status(void); + void create_title_bar(void) { int rows, cols; @@ -49,38 +53,14 @@ void title_bar_title(void) void title_bar_connected(void) { - int rows, cols; - getmaxyx(stdscr, rows, cols); - - wattron(title_bar, COLOR_PAIR(4)); - mvwaddch(title_bar, 0, cols - 14, '['); - wattroff(title_bar, COLOR_PAIR(4)); - - mvwprintw(title_bar, 0, cols - 13, " ...online "); - - wattron(title_bar, COLOR_PAIR(4)); - mvwaddch(title_bar, 0, cols - 2, ']'); - wattroff(title_bar, COLOR_PAIR(4)); - - dirty = TRUE; + connected = TRUE; + _title_bar_draw_status(); } void title_bar_disconnected(void) { - int rows, cols; - getmaxyx(stdscr, rows, cols); - - wattron(title_bar, COLOR_PAIR(4)); - mvwaddch(title_bar, 0, cols - 14, '['); - wattroff(title_bar, COLOR_PAIR(4)); - - mvwprintw(title_bar, 0, cols - 13, " ..offline "); - - wattron(title_bar, COLOR_PAIR(4)); - mvwaddch(title_bar, 0, cols - 2, ']'); - wattroff(title_bar, COLOR_PAIR(4)); - - dirty = TRUE; + connected = FALSE; + _title_bar_draw_status(); } void title_bar_refresh(void) @@ -99,6 +79,11 @@ void title_bar_show(const char * const title) current_title = (char *) malloc((strlen(title) + 1) * sizeof(char)); strcpy(current_title, title); + _title_bar_draw_title(); +} + +void _title_bar_draw_title(void) +{ wmove(title_bar, 0, 0); int i; for (i = 0; i < 45; i++) @@ -108,3 +93,23 @@ void title_bar_show(const char * const title) dirty = TRUE; } +void _title_bar_draw_status(void) +{ + int rows, cols; + getmaxyx(stdscr, rows, cols); + + wattron(title_bar, COLOR_PAIR(4)); + mvwaddch(title_bar, 0, cols - 14, '['); + wattroff(title_bar, COLOR_PAIR(4)); + + if (connected == TRUE) + mvwprintw(title_bar, 0, cols - 13, " ...online "); + else + mvwprintw(title_bar, 0, cols - 13, " ..offline "); + + wattron(title_bar, COLOR_PAIR(4)); + mvwaddch(title_bar, 0, cols - 2, ']'); + wattroff(title_bar, COLOR_PAIR(4)); + + dirty = TRUE; +} -- cgit 1.4.1-2-gfad0