about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-04-20 01:24:24 +0100
committerJames Booth <boothj5@gmail.com>2012-04-20 01:24:24 +0100
commitea261b8852a7c1dad462e71ed0442c00a142adc2 (patch)
treea0fbbd55f65f98862297c7bb1537d3a3cb4c8956
parent2a22ec9266abcb83b7ed7a282486d63bb6b7d7a2 (diff)
downloadprofani-tty-ea261b8852a7c1dad462e71ed0442c00a142adc2.tar.gz
Refactored title bar status
-rw-r--r--title_bar.c61
1 files 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;
+}