From bd5453002efc452efbc7ee55526e6254b30a151e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 26 Mar 2014 19:14:28 -0400 Subject: [PATCH] a few more fixes --- src/chat_commands.c | 6 ++++++ src/global_commands.c | 6 ++++++ src/groupchat.c | 6 ++++++ src/line_info.c | 16 +++++++++++++--- src/line_info.h | 7 +++++-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/chat_commands.c b/src/chat_commands.c index 9850861..de2cdd6 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -42,6 +42,10 @@ extern uint8_t max_file_senders_index; void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { + struct history *hst = self->chatwin->hst; + line_info_clear(hst); + struct line_info *start = hst->line_start; + if (argc == 1) { if (!strcmp(argv[1], "global")) { execute(window, self, m, "/help", GLOBAL_COMMAND_MODE); @@ -84,6 +88,8 @@ void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg msg = " * Use ESC key to toggle history scroll mode\n"; line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN); + + hst->line_start = start; } void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) diff --git a/src/global_commands.c b/src/global_commands.c index f048ccd..71610f4 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -372,6 +372,10 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { + struct history *hst = self->chatwin->hst; + line_info_clear(hst); + struct line_info *start = hst->line_start; + uint8_t *msg = "Global commands:"; line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN); @@ -409,6 +413,8 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a msg = " * Argument messages must be enclosed in quotation marks.\n" " * Use ctrl-o and ctrl-p to navigate through the tabs.\n"; line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN); + + hst->line_start = start; } void cmd_quit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) diff --git a/src/groupchat.c b/src/groupchat.c index b2991cd..2220382 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -106,6 +106,10 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum) static void print_groupchat_help(ToxWindow *self) { + struct history *hst = self->chatwin->hst; + line_info_clear(hst); + struct line_info *start = hst->line_start; + uint8_t *msg = "Group chat commands:"; line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN); @@ -136,6 +140,8 @@ static void print_groupchat_help(ToxWindow *self) line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN); msg = " * Notice, some friends will be missing names while finding peers\n"; line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, 0); + + hst->line_start = start; } static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum, diff --git a/src/line_info.c b/src/line_info.c index 3dbda18..28a053d 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -168,14 +168,18 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na getmaxyx(self->window, y2, x2); getyx(self->chatwin->history, y, x); + if (x2 <= SIDEBAR_WIDTH) + return; + int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */ int lines = (1 + newlines + (len / (x2 - offst))); - hst->queue += lines; + hst->queue_lns += lines; + ++hst->queue; int max_y = self->is_prompt ? y2 : y2 - CHATBOX_HEIGHT; /* move line_start forward proportionate to the number of new lines */ - if (y + hst->queue - 1 >= max_y) { + if (y + hst->queue_lns - hst->queue >= max_y) { while (lines > 0 && hst->line_start->next) { lines -= (1 + hst->line_start->len / (x2 - offst)); hst->line_start = hst->line_start->next; @@ -193,7 +197,11 @@ void line_info_print(ToxWindow *self) int y2, x2; getmaxyx(self->window, y2, x2); + if (x2 <= SIDEBAR_WIDTH) + return; + ctx->hst->queue = 0; + ctx->hst->queue_lns = 0; if (self->is_groupchat) wmove(win, 0, 0); @@ -201,11 +209,12 @@ void line_info_print(ToxWindow *self) wmove(win, 2, 0); struct line_info *line = ctx->hst->line_start->next; + int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; int numlines = 0; while(line && numlines <= y2) { uint8_t type = line->type; - numlines += line->len / x2; + numlines += line->len / (x2 - offst); switch (type) { case OUT_MSG: @@ -386,4 +395,5 @@ void line_info_onKey(ToxWindow *self, wint_t key) void line_info_clear(struct history *hst) { hst->line_start = hst->line_end; + hst->start_id = hst->line_start->id; } diff --git a/src/line_info.h b/src/line_info.h index 3f4f4b1..6ac1f2c 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -20,7 +20,7 @@ * */ -#define MAX_HISTORY 200 +#define MAX_HISTORY 1000 enum { SYS_MSG, @@ -55,7 +55,10 @@ struct history { uint32_t start_id; /* keeps track of where line_start should be when at bottom of history */ uint32_t line_items; bool scroll_mode; - uint8_t queue; /* keeps track of lines added between window refreshes */ + + /* keeps track of lines added between window refreshes */ + uint8_t queue; + uint8_t queue_lns; }; /* adds a line to history (also moves line_start and/or line_root forward if necessary) */