about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-03-01 00:40:51 +0000
committerJames Booth <boothj5@gmail.com>2012-03-01 00:40:51 +0000
commit2acf15de0de6cb42e1dcf08b15a686e05c62b08e (patch)
tree4eb5a5c69fb86aa4643e5ca4cfccad7a5656ac84
parent1cc22c23f9db20504b8c5aa0a95e91079a6d88e8 (diff)
downloadprofani-tty-2acf15de0de6cb42e1dcf08b15a686e05c62b08e.tar.gz
Close win now has return value
-rw-r--r--command.c5
-rw-r--r--windows.c31
-rw-r--r--windows.h2
3 files changed, 24 insertions, 14 deletions
diff --git a/command.c b/command.c
index c5ef816c..da2df857 100644
--- a/command.c
+++ b/command.c
@@ -177,11 +177,8 @@ static int _cmd_msg(char *inp)
 
 static int _cmd_close(char *inp)
 {
-    if (win_in_chat()) {
-        win_close_win();
-    } else {
+    if (!win_close_win())
         cons_bad_command(inp);
-    }
     
     return TRUE;
 }
diff --git a/windows.c b/windows.c
index 4d1f2900..5e523711 100644
--- a/windows.c
+++ b/windows.c
@@ -28,8 +28,13 @@
 
 #define CONS_WIN_TITLE "_cons"
 
+// holds console at index 0 and chat wins 1 through to 9
 static struct prof_win _wins[10];
+
+// the window currently being displayed
 static int _curr_prof_win = 0;
+
+// shortcut pointer to console window
 static WINDOW * _cons_win = NULL;
 
 static void _create_windows(void);
@@ -83,18 +88,26 @@ void gui_close(void)
     endwin();
 }
 
-void win_close_win(void)
+int win_close_win(void)
 {
-    // reset the chat win to unused
-    strcpy(_wins[_curr_prof_win].from, "");
-    wclear(_wins[_curr_prof_win].win);
+    if (win_in_chat()) {
+        // reset the chat win to unused
+        strcpy(_wins[_curr_prof_win].from, "");
+        wclear(_wins[_curr_prof_win].win);
 
-    // set it as inactive in the status bar
-    status_bar_inactive(_curr_prof_win);
+        // set it as inactive in the status bar
+        status_bar_inactive(_curr_prof_win);
+        
+        // go back to console window
+        _curr_prof_win = 0;
+        title_bar_title();
     
-    // go back to console window
-    _curr_prof_win = 0;
-    title_bar_title();
+        // success
+        return 1;
+    } else {
+        // didn't close anything
+        return 0;
+    }
 }
 
 int win_in_chat(void)
diff --git a/windows.h b/windows.h
index a2c8985c..9310b3f9 100644
--- a/windows.h
+++ b/windows.h
@@ -48,7 +48,7 @@ void title_bar_connected(void);
 void title_bar_disconnected(void);
 
 // main window actions
-void win_close_win(void);
+int win_close_win(void);
 int win_in_chat(void);
 char *win_get_recipient(void);
 void win_show_incomming_msg(char *from, char *message);