diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 9197485f..ac35c789 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -113,6 +113,8 @@ static int _inp_rl_win_pageup_handler(int count, int key); static int _inp_rl_win_pagedown_handler(int count, int key); static int _inp_rl_subwin_pageup_handler(int count, int key); static int _inp_rl_subwin_pagedown_handler(int count, int key); +static int _inp_rl_win_lineup_handler(int count, int key); +static int _inp_rl_win_linedown_handler(int count, int key); static int _inp_rl_startup_hook(void); void @@ -370,6 +372,9 @@ _inp_rl_addfuncs(void) rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler); rl_add_funmap_entry("prof_subwin_pagedown", _inp_rl_subwin_pagedown_handler); rl_add_funmap_entry("prof_win_clear", _inp_rl_win_clear_handler); + + rl_add_funmap_entry("prof_win_lineup", _inp_rl_win_lineup_handler); + rl_add_funmap_entry("prof_win_linedown", _inp_rl_win_linedown_handler); } // Readline callbacks @@ -420,6 +425,9 @@ _inp_rl_startup_hook(void) rl_bind_keyseq("\\e[6~", _inp_rl_win_pagedown_handler); rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler); + rl_bind_keyseq("\\ep", _inp_rl_win_lineup_handler); + rl_bind_keyseq("\\el", _inp_rl_win_linedown_handler); + rl_bind_key('\t', _inp_rl_tab_handler); // unbind unwanted mappings @@ -611,6 +619,22 @@ _inp_rl_win_pagedown_handler(int count, int key) return 0; } +static int +_inp_rl_win_lineup_handler(int count, int key) +{ + ProfWin *current = wins_get_current(); + win_line_up(current); + return 0; +} + +static int +_inp_rl_win_linedown_handler(int count, int key) +{ + ProfWin *current = wins_get_current(); + win_line_down(current); + return 0; +} + static int _inp_rl_subwin_pageup_handler(int count, int key) { diff --git a/src/ui/window.c b/src/ui/window.c index 2c84aef9..5a4c06a1 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -520,6 +520,62 @@ win_page_down(ProfWin *window) } } +void +win_line_up(ProfWin *window) +{ + int rows = getmaxy(stdscr); + int y = getcury(window->layout->win); + int page_space = rows - 4; + int *page_start = &(window->layout->y_pos); + + *page_start -= 1; + + // went past beginning, show first page + if (*page_start < 0) + *page_start = 0; + + window->layout->paged = 1; + win_update_virtual(window); + + // switch off page if last line and space line visible + if ((y) - *page_start == page_space) { + window->layout->paged = 0; + } +} + +void +win_line_down(ProfWin *window) +{ + window->layout->paged = 0; + + int win_rows = getmaxy(stdscr) - 4; + int win_curr_row = getcury(window->layout->win); + int curr_y_pos = window->layout->y_pos; + if (win_curr_row - curr_y_pos < win_rows) { + return; + } + + int *page_start = &(window->layout->y_pos); + + *page_start += 1; + + // only got half a screen, show full screen + if ((win_curr_row - (*page_start)) < win_rows) + *page_start = win_curr_row - win_rows; + + // went past end, show full screen + else if (*page_start >= win_curr_row) + *page_start = win_curr_row - win_rows - 1; + + window->layout->paged = 1; + win_update_virtual(window); + + // switch off page if last line and space line visible + if ((win_curr_row) - *page_start == win_rows) { + window->layout->paged = 0; + } +} + void win_sub_page_down(ProfWin *window) { diff --git a/src/ui/window.h b/src/ui/window.h index cc9ae8df..67955f7d 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -79,5 +79,7 @@ void win_page_up(ProfWin *window); void win_page_down(ProfWin *window); void win_sub_page_down(ProfWin *window); void win_sub_page_up(ProfWin *window); +void win_line_up(ProfWin *window); +void win_line_down(ProfWin *window); #endif