about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorImmae <ismael.bouya@normalesup.org>2014-06-19 15:48:02 +0200
committerJames Booth <boothj5@gmail.com>2014-06-23 20:23:07 +0100
commit5e841febd0c742745450598c4068b87ddca069b5 (patch)
tree7bf7ae3a4df2fb098891e16e7bae36416e8538cf
parentd668d15081f3d38d618457cb9016100acc6877dc (diff)
downloadprofani-tty-5e841febd0c742745450598c4068b87ddca069b5.tar.gz
Added horizontal scroll for resized windows
Signed-off-by: James Booth <boothj5@gmail.com>
-rw-r--r--src/ui/core.c34
-rw-r--r--src/ui/window.c4
-rw-r--r--src/ui/window.h1
3 files changed, 36 insertions, 3 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 84fcebfd..a02ea39e 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2048,10 +2048,14 @@ _win_handle_page(const wint_t * const ch)
 {
     ProfWin *current = wins_get_current();
     int rows = getmaxy(stdscr);
+    int cols = getmaxx(stdscr);
+    int x = getmaxx(current->win);
     int y = getcury(current->win);
 
     int page_space = rows - 4;
+    int horiz_page_space = cols;
     int *page_start = &(current->y_pos);
+    int *horiz_page_start = &(current->x_pos);
 
     if (prefs_get_boolean(PREF_MOUSE)) {
         MEVENT mouse_event;
@@ -2090,8 +2094,34 @@ _win_handle_page(const wint_t * const ch)
         }
     }
 
+    // ctrl+P
+    if (*ch == 16) {
+        *horiz_page_start -= horiz_page_space;
+
+        // went past beginning, show first page
+        if (*horiz_page_start < 0)
+            *horiz_page_start = 0;
+
+        current->paged = 1;
+        win_update_virtual(current);
+
+    // ctrl+N
+    } else if (*ch == 14) {
+        *horiz_page_start += horiz_page_space;
+
+        // only got half a screen, show full screen
+        if ((x - (*horiz_page_start)) < horiz_page_space)
+            *horiz_page_start = x - horiz_page_space;
+
+        // went past end, show full screen
+        else if (*horiz_page_start >= x)
+          *horiz_page_start = x - horiz_page_space;
+
+        current->paged = 1;
+        win_update_virtual(current);
+
     // page up
-    if (*ch == KEY_PPAGE) {
+    } else if (*ch == KEY_PPAGE) {
         *page_start -= page_space;
 
         // went past beginning, show first page
@@ -2118,7 +2148,7 @@ _win_handle_page(const wint_t * const ch)
     }
 
     // switch off page if last line visible
-    if ((y-1) - *page_start == page_space) {
+    if ((y-1) - *page_start == page_space && *horiz_page_start == 0) {
         current->paged = 0;
     }
 }
diff --git a/src/ui/window.c b/src/ui/window.c
index 11559421..0f4906c5 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -48,6 +48,7 @@ win_create(const char * const title, int cols, win_type_t type)
     new_win->win = newpad(PAD_SIZE, cols);
     wbkgd(new_win->win, COLOUR_TEXT);
     new_win->y_pos = 0;
+    new_win->x_pos = 0;
     new_win->paged = 0;
     new_win->unread = 0;
     new_win->history_shown = 0;
@@ -118,7 +119,7 @@ win_update_virtual(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
-    pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
+    pnoutrefresh(window->win, window->y_pos, window->x_pos, 1, 0, rows-3, cols-1);
 }
 
 void
@@ -131,6 +132,7 @@ win_move_to_end(ProfWin *window)
     int size = rows - 3;
 
     window->y_pos = y - (size - 1);
+    window->x_pos = 0;
     if (window->y_pos < 0) {
         window->y_pos = 0;
     }
diff --git a/src/ui/window.h b/src/ui/window.h
index 4d10874c..a9cabe17 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -51,6 +51,7 @@ typedef struct prof_win_t {
     win_type_t type;
     gboolean is_otr;
     gboolean is_trusted;
+    int x_pos;
     int y_pos;
     int paged;
     int unread;