1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-04 09:46:45 +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

@ -15,6 +15,7 @@
#include "misc_tools.h"
#include "groupchat.h"
#include "prompt.h"
#include "toxic_strings.h"
extern char *DATA_FILE;
extern int store_data(Tox *m, char *path);
@ -308,6 +309,22 @@ static void groupchat_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: completes peer name */
if (ctx->len > 0) {
int diff;
@ -371,6 +388,9 @@ static void groupchat_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") == 0) {
set_active_window(0);