about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-03 09:57:03 +0000
committerJames Booth <boothj5@gmail.com>2012-02-03 09:57:03 +0000
commitae43a57e6a35b91a0bacb7ec112d911377a92d87 (patch)
tree73b428805706995555a66e09d2e57de0be3207a0
parentcb4d79186b5ee66af85798ed4b8d22f946f13d01 (diff)
downloadprofani-tty-ae43a57e6a35b91a0bacb7ec112d911377a92d87.tar.gz
Added scrolling input window
-rw-r--r--profanity.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/profanity.c b/profanity.c
index 44e4f5b5..39116b60 100644
--- a/profanity.c
+++ b/profanity.c
@@ -5,6 +5,12 @@
 #include <strophe/strophe.h>
 
 static FILE *logp;
+static WINDOW *incoming_border;
+static WINDOW *outgoing_border;
+static WINDOW *incoming;
+static WINDOW *outgoing;
+static int incoming_ypos = 0;
+static int inc_scroll_max = 0;
 
 xmpp_log_t *xmpp_get_file_logger();
 
@@ -26,6 +32,9 @@ void print_title(void);
 
 void close(void);
 
+WINDOW *create_win(int, int, int, int, int);
+void create_conversation(void);
+
 int main(void)
 {   
     int ypos = 2;
@@ -68,7 +77,11 @@ int main(void)
     xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);
     
     clear();
+    print_title();
     refresh();
+    move(3, 0);
+
+    create_conversation();
 
     xmpp_run(ctx);
 
@@ -100,10 +113,18 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
 
     intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
 
-    printw("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), 
-        intext);
+    char in_line[100];    
+    sprintf(in_line, "%s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext);
 
-    refresh();
+    if (incoming_ypos == inc_scroll_max-1) {
+        scroll(incoming);
+        mvwaddstr(incoming, incoming_ypos-1, 0, in_line);
+    } else {
+        mvwaddstr(incoming, incoming_ypos, 0, in_line);
+        incoming_ypos++;
+    }
+
+    wrefresh(incoming);
 
     reply = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(reply, "message");
@@ -130,7 +151,6 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     return 1;
 }
 
-
 xmpp_log_t *xmpp_get_file_logger()
 {
     return (xmpp_log_t*) &file_log;
@@ -182,6 +202,52 @@ void init(void)
     attron(COLOR_PAIR(1));
 }
 
+WINDOW *create_win(int height, int width, int starty, int startx, int border)
+{   
+    WINDOW *local_win;
+
+    local_win = newwin(height, width, starty, startx);
+    if (border)    
+        box(local_win, 0 , 0);     
+    wrefresh(local_win);
+
+    return local_win;
+}
+
+void create_conversation()
+{
+    int rows, cols;
+    char *title = "PROFANITY";
+
+    getmaxyx(stdscr, rows, cols);
+    
+    curs_set(0);
+    attron(COLOR_PAIR(3));
+    mvprintw(1, (cols - strlen(title))/2, title);
+    attroff(COLOR_PAIR(3));
+
+    int in_height, in_width, in_y, in_x;
+    int out_height, out_width, out_y, out_x;
+
+    out_height = 5;
+    out_width = cols;
+    out_y = rows - 5;
+    out_x = 0;
+
+    in_height = (rows - 3) - (out_height);
+    in_width = cols;
+    in_y = 3;
+    in_x = 0;
+    
+    incoming_border = create_win(in_height, in_width, in_y, in_x, 1);
+    outgoing_border = create_win(out_height, out_width, out_y, out_x, 1);
+    inc_scroll_max = in_height-2;
+    incoming = create_win(in_height-2, in_width-2, in_y+1, in_x+1, 0);
+    scrollok(incoming, TRUE);
+    outgoing = create_win(out_height-2, out_width-2, out_y+1, out_x+1, 0);
+    
+}
+
 void print_title(void)
 {
     int rows, cols;