1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-01 16:16:46 +02:00

add line history with up/down keys

This commit is contained in:
Jfreegman
2013-12-11 00:10:09 -05:00
parent ccc0640dab
commit 9a5a598c5a
8 changed files with 148 additions and 5 deletions

View File

@ -342,9 +342,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
else if (key == KEY_END) { /* END key: move cursor to end of line */
if (ctx->pos != ctx->len) {
ctx->pos = ctx->len;
int end_y = (ctx->len / x2) + (y2 - CURS_Y_OFFSET);
int end_x = ctx->len % x2;
wmove(self->window, end_y, end_x);
mv_curs_end(self->window, ctx->len, y2, x2);
}
}
@ -370,6 +368,22 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
}
}
else if (key == KEY_UP) { /* fetches previous item in history */
if (ctx->hst_pos >= 0) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, &ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_UP);
mv_curs_end(self->window, ctx->len, y2, x2);
}
}
else if (key == KEY_DOWN) { /* fetches next item in history */
if (ctx->hst_pos < ctx->hst_tot) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, &ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_DWN);
mv_curs_end(self->window, ctx->len, y2, x2);
}
}
else if (key == '\t') { /* TAB key: command */
if (ctx->len > 1 && ctx->line[0] == '/') {
int diff = complete_line(ctx->line, &ctx->pos, &ctx->len, chat_cmd_list, AC_NUM_CHAT_COMMANDS,
@ -414,6 +428,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
wclrtobot(self->window);
bool close_win = false;
if (!string_is_empty(line))
add_line_to_hist(ctx->line, ctx->len, ctx->ln_history, &ctx->hst_tot, &ctx->hst_pos);
if (line[0] == '/') {
if (close_win = !strcmp(line, "/close")) {
int f_num = self->num;