1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Paging in console window

This commit is contained in:
James Booth 2012-03-05 00:06:24 +00:00
parent 20c05b2f77
commit 0ddf97e016
4 changed files with 69 additions and 6 deletions

View File

@ -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) &&

View File

@ -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();
}
}

View File

@ -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,

View File

@ -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);