mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 21:03:27 +01:00
few fixes
This commit is contained in:
parent
3baa830afb
commit
29b549e677
@ -182,9 +182,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
|
||||
void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
struct history *hst = self->chatwin->hst;
|
||||
line_info_cleanup(hst);
|
||||
line_info_init(hst);
|
||||
line_info_clear(self->chatwin->hst);
|
||||
}
|
||||
|
||||
void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
@ -270,7 +268,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
} else if (self->is_prompt) {
|
||||
uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, myid);
|
||||
log_enable(self->name, &myid, log);
|
||||
log_enable(self->name, myid, log);
|
||||
} else if (self->is_groupchat) {
|
||||
log_enable(self->name, NULL, log);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "line_info.h"
|
||||
#include "groupchat.h"
|
||||
|
||||
void line_info_init(struct history *hst)
|
||||
{
|
||||
@ -156,19 +157,27 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
|
||||
hst->line_root = tmp;
|
||||
}
|
||||
|
||||
int newlines = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; msg[i]; ++i) {
|
||||
if (msg[i] == '\n')
|
||||
++newlines;
|
||||
}
|
||||
|
||||
int y, y2, x, x2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
getyx(self->chatwin->history, y, x);
|
||||
|
||||
int n = self->is_prompt ? 0 : CHATBOX_HEIGHT;
|
||||
int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */
|
||||
int lines = 1 + (len / (x2 - offst));
|
||||
|
||||
/* move line_start forward proportionate to the number of new rows */
|
||||
if (y >= y2 - n) {
|
||||
int i;
|
||||
int lines = 1 + (len / x2);
|
||||
int max_y = self->is_prompt ? y2 : y2 - CHATBOX_HEIGHT;
|
||||
|
||||
/* move line_start forward proportionate to the number of new lines */
|
||||
if (y >= max_y) {
|
||||
while (lines > 0 && hst->line_start->next) {
|
||||
lines -= (1 + hst->line_start->len / x2);
|
||||
lines -= (1 + hst->line_start->len / (x2 - offst));
|
||||
hst->line_start = hst->line_start->next;
|
||||
++hst->start_id;
|
||||
}
|
||||
@ -371,3 +380,8 @@ void line_info_onKey(ToxWindow *self, wint_t key)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void line_info_clear(struct history *hst)
|
||||
{
|
||||
hst->line_start = hst->line_end;
|
||||
}
|
||||
|
@ -55,12 +55,25 @@ 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;
|
||||
int y;
|
||||
int old_y;
|
||||
};
|
||||
|
||||
/* adds a line to history (also moves line_start and/or line_root forward if necessary) */
|
||||
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, uint8_t *msg,
|
||||
uint8_t type, uint8_t bold, uint8_t colour);
|
||||
void line_info_cleanup(struct history *hst);
|
||||
void line_info_toggle_scroll(ToxWindow *self, bool scroll);
|
||||
void line_info_init(struct history *hst);
|
||||
|
||||
/* Prints a section of history starting at line_start */
|
||||
void line_info_print(ToxWindow *self);
|
||||
|
||||
/* frees all history lines */
|
||||
void line_info_cleanup(struct history *hst);
|
||||
|
||||
/* Toggles scroll mode for current window */
|
||||
void line_info_toggle_scroll(ToxWindow *self, bool scroll);
|
||||
|
||||
/* clears the screen (does not delete anything) */
|
||||
void line_info_clear(struct history *hst);
|
||||
|
||||
void line_info_init(struct history *hst);
|
||||
void line_info_onKey(ToxWindow *self, wint_t key);
|
||||
|
@ -144,7 +144,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
if (ctx->pos > 0) {
|
||||
del_char_buf_bck(ctx->line, &ctx->pos, &ctx->len);
|
||||
wmove(ctx->history, y, x-1); /* not necessary but fixes a display glitch */
|
||||
ctx->scroll = false;
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
@ -153,7 +152,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
else if (key == KEY_DC) { /* DEL key: Remove character at pos */
|
||||
if (ctx->pos != ctx->len) {
|
||||
del_char_buf_frnt(ctx->line, &ctx->pos, &ctx->len);
|
||||
ctx->scroll = false;
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
@ -246,7 +244,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
if (ctx->len < (MAX_STR_SIZE-1)) {
|
||||
add_char_to_buf(ctx->line, &ctx->pos, &ctx->len, key);
|
||||
ctx->scroll = true;
|
||||
}
|
||||
}
|
||||
/* RETURN key: execute command */
|
||||
@ -303,10 +300,8 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
bool edge = (ctx->len + p_ofst) % px2 == 0;
|
||||
|
||||
/* move point of line origin up when input scrolls screen down */
|
||||
if (ctx->scroll && edge && botm) {
|
||||
if (edge && botm)
|
||||
--ctx->orig_y;
|
||||
ctx->scroll = false;
|
||||
}
|
||||
|
||||
} else { /* Mark point of origin for new line */
|
||||
ctx->orig_y = y;
|
||||
|
@ -189,7 +189,6 @@ struct ChatContext {
|
||||
/* specific for prompt */
|
||||
bool at_bottom; /* true if line end is at bottom of window */
|
||||
int orig_y; /* y axis point of line origin */
|
||||
bool scroll; /* used for prompt window hack to determine when to scroll down */
|
||||
};
|
||||
|
||||
/* Start file transfer code */
|
||||
|
Loading…
Reference in New Issue
Block a user