about summary refs log tree commit diff stats
path: root/app.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-07 22:59:47 +0000
committerJames Booth <boothj5@gmail.com>2012-02-07 22:59:47 +0000
commite2665944cbd86b4f7516d9bb4f95f581b699923c (patch)
tree06679f935b5c6fba56bc29a5b341d8e686432b4d /app.c
parentbb3878bc76588838379be3df1dfe1d0d100ff59b (diff)
downloadprofani-tty-e2665944cbd86b4f7516d9bb4f95f581b699923c.tar.gz
SImple window switching for message and console
Diffstat (limited to 'app.c')
-rw-r--r--app.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/app.c b/app.c
index e7cf7589..7830c3b2 100644
--- a/app.c
+++ b/app.c
@@ -7,37 +7,49 @@
 #include "windows.h"
 #include "jabber.h"
 
+#define CHAT 0
+#define CONS 1
+
 static void main_event_loop(void);
 
 void start_profanity(void)
 {
     char cmd[50];
     while (TRUE) {
-        cmd_get_command_str(cmd);
+        inp_get_command_str(cmd);
 
         if (strcmp(cmd, "/quit") == 0) {
             break;
+        } else if (strncmp(cmd, "/help", 5) == 0) {
+            cons_help();
+            cons_show();
+            inp_clear();
         } else if (strncmp(cmd, "/connect ", 9) == 0) {
             char *user;
             user = strndup(cmd+9, strlen(cmd)-9);
 
             bar_print_message("Enter password:");
             char passwd[20];
-            cmd_get_password(passwd);
+            inp_get_password(passwd);
 
             bar_print_message(user);
             jabber_connect(user, passwd);
+            chat_show();
             main_event_loop();
             break;
         } else {
-            cmd_clear();
+            cons_bad_command(cmd);
+            cons_show();
+            inp_clear();
         }
     }
 }
 
 static void main_event_loop(void)
 {
-    cmd_non_block();
+    int showing = CHAT;
+
+    inp_non_block();
 
     while(TRUE) {
         int ch = ERR;
@@ -50,9 +62,20 @@ static void main_event_loop(void)
         
             // handle incoming messages
             jabber_process_events();
+            if (showing == CHAT) {
+                chat_show();
+            }
 
+            // determine if they changed windows
+            if (ch == KEY_F(1)) {
+                cons_show();
+                showing = CONS;
+            } else if (ch == KEY_F(2)) {
+                chat_show();
+                showing = CHAT;
+            }
             // get another character from the command box
-            cmd_poll_char(&ch, command, &size);
+            inp_poll_char(&ch, command, &size);
         }
 
         // null terminate the input    
@@ -61,10 +84,19 @@ static void main_event_loop(void)
         // newline was hit, check if /quit command issued
         if (strcmp(command, "/quit") == 0) {
             break;
+        } else if (strncmp(command, "/help", 5) == 0) {
+            cons_help();
+            if (showing == CONS) {
+                cons_show();
+            }
+            inp_clear();
         } else {
             jabber_send(command);
             show_outgoing_msg("me", command);
-            cmd_clear();
+            if (showing == CHAT) {
+                chat_show();
+            }
+            inp_clear();
         }
     }