about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-03-05 00:06:24 +0000
committerJames Booth <boothj5@gmail.com>2012-03-05 00:06:24 +0000
commit0ddf97e0166e22b9fc7311dc42f555a264bef2b9 (patch)
tree4c0b811632ddd8bb34b6c69dec743d6519a5be42
parent20c05b2f7760aaa669e820b7f698b7f366d2f10d (diff)
downloadprofani-tty-0ddf97e0166e22b9fc7311dc42f555a264bef2b9.tar.gz
Paging in console window
-rw-r--r--input_win.c2
-rw-r--r--profanity.c2
-rw-r--r--windows.c67
-rw-r--r--windows.h4
4 files changed, 69 insertions, 6 deletions
diff --git a/input_win.c b/input_win.c
index f1329047..0caa8264 100644
--- a/input_win.c
+++ b/input_win.c
@@ -199,7 +199,7 @@ static int _handle_edit(int ch, char *input, int *size)
 
 static int _printable(int ch)
 {
-   return (ch != ERR && ch != '\n' &&
+   return (ch != ERR && ch != '\n' && ch != KEY_PPAGE && ch != KEY_NPAGE &&
             ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) && 
             ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) &&
             ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) &&
diff --git a/profanity.c b/profanity.c
index 2603235c..9b7d7674 100644
--- a/profanity.c
+++ b/profanity.c
@@ -47,11 +47,13 @@ void profanity_run(void)
             gui_refresh();
             jabber_process_events();
             win_handle_switch(&ch);
+            win_handle_page(&ch);
             inp_poll_char(&ch, inp, &size);
         }
 
         inp[size++] = '\0';
         cmd_result = process_input(inp);
+        win_page_off();
     }
 
 }
diff --git a/windows.c b/windows.c
index 9e846f05..114626f7 100644
--- a/windows.c
+++ b/windows.c
@@ -27,6 +27,7 @@
 #include "util.h"
 
 #define CONS_WIN_TITLE "_cons"
+#define PAD_SIZE 200
 #define NUM_WINS 10
 
 // holds console at index 0 and chat wins 1 through to 9
@@ -260,6 +261,52 @@ void win_handle_switch(int *ch)
     }
 }
 
+void win_page_off(void)
+{
+    int rows, cols;
+        getmaxyx(stdscr, rows, cols);
+    if (_curr_prof_win == 0) {
+        _wins[0].paged = 0;
+        
+        int y, x;
+        getyx(_cons_win, y, x);
+
+        int size = rows - 3;
+
+        _wins[0].y_pos = y - (size - 1);
+        if (_wins[0].y_pos < 0)
+            _wins[0].y_pos = 0;
+    }
+}
+
+void win_handle_page(int *ch)
+{
+    if (*ch == KEY_PPAGE) {
+        int rows, cols;
+        getmaxyx(stdscr, rows, cols);
+
+        if (_curr_prof_win == 0) {
+            _wins[0].y_pos = _wins[0].y_pos - (rows - 4);
+            if (_wins[0].y_pos < 0)
+                _wins[0].y_pos = 0;
+        }
+           
+        _wins[0].paged = 1;
+    } else if (*ch == KEY_NPAGE) {
+        int rows, cols, y, x;
+        getmaxyx(stdscr, rows, cols);
+        getyx(_cons_win, y, x);
+
+        if (_curr_prof_win == 0) {
+            _wins[0].y_pos = _wins[0].y_pos + (rows - 4);
+            if (_wins[0].y_pos >= y)
+                _wins[0].y_pos = y - 1;
+        }
+           
+        _wins[0].paged = 1;
+    }
+}
+
 static void _create_windows(void)
 {
     int rows, cols;
@@ -268,7 +315,9 @@ static void _create_windows(void)
     // create the console window in 0
     struct prof_win cons;
     strcpy(cons.from, CONS_WIN_TITLE);
-    cons.win = newwin(rows-3, cols, 1, 0);
+    cons.win = newpad(PAD_SIZE, cols);
+    cons.y_pos = 0;
+    cons.paged = 0;
     scrollok(cons.win, TRUE);
 
     _wins[0] = cons;
@@ -278,7 +327,7 @@ static void _create_windows(void)
     _win_show_time(_cons_win);
     wprintw(_cons_win, "Welcome to Profanity.\n");
     touchwin(_cons_win);
-    wrefresh(_cons_win);
+    prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);
     
     // create the chat windows
     int i;
@@ -354,9 +403,17 @@ static void _win_show_message(WINDOW *win, char *message)
 
 static void _current_window_refresh()
 {
-    WINDOW *current = _wins[_curr_prof_win].win;
-    touchwin(current);
-    wrefresh(current);
+    int rows, cols;
+    getmaxyx(stdscr, rows, cols);
+    
+    if (_curr_prof_win == 0) {
+        touchwin(_cons_win);
+        prefresh(_cons_win, _wins[0].y_pos, 0, 1, 0, rows-3, cols-1);
+    } else {
+        WINDOW *current = _wins[_curr_prof_win].win;
+        touchwin(current);
+        wrefresh(current);
+    }
 }
 
 static void _show_status_string(WINDOW *win, char *from, char *show, char *status, 
diff --git a/windows.h b/windows.h
index cc0b75f0..377d6092 100644
--- a/windows.h
+++ b/windows.h
@@ -28,6 +28,8 @@
 struct prof_win {
     char from[100];
     WINDOW *win;
+    int y_pos;
+    int paged;
 };
 
 // gui startup and shutdown
@@ -54,6 +56,8 @@ char *win_get_recipient(void);
 void win_show_incomming_msg(char *from, char *message);
 void win_show_outgoing_msg(char *from, char *to, char *message);
 void win_handle_switch(int *ch);
+void win_handle_page(int *ch);
+void win_page_off(void);
 void win_contact_online(char *from, char *show, char *status);
 void win_contact_offline(char *from, char *show, char *status);