diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-06 15:37:15 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-06 15:37:15 +0000 |
commit | 9cddd796ffef383893b5fd4e228f4d18673a77bd (patch) | |
tree | 995d7305b6d749eefbbeaf922f9fecf0c3031b63 /status.c | |
parent | 7fef12b4910fccf1b3c390f39e620448e5a9415b (diff) |
Prompt history.
Diffstat (limited to 'status.c')
-rw-r--r-- | status.c | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.52 2008-12-08 16:19:51 nicm Exp $ */ +/* $Id: status.c,v 1.53 2009-01-06 15:37:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -32,6 +32,8 @@ char *status_replace(struct session *, char *, time_t); size_t status_width(struct winlink *); char *status_print(struct session *, struct winlink *, struct grid_cell *); +void status_prompt_add_history(struct client *); + /* Draw status for client on the last lines of given context. */ void status_redraw(struct client *c) @@ -530,8 +532,37 @@ status_prompt_key(struct client *c, int key) c->flags |= CLIENT_STATUS; } break; + case KEYC_UP: + if (ARRAY_LENGTH(&c->prompt_hdata) == 0) + break; + xfree(c->prompt_buffer); + + c->prompt_buffer = xstrdup(ARRAY_ITEM(&c->prompt_hdata, + ARRAY_LENGTH(&c->prompt_hdata) - 1 - c->prompt_hindex)); + if (c->prompt_hindex != ARRAY_LENGTH(&c->prompt_hdata) - 1) + c->prompt_hindex++; + + c->prompt_index = strlen(c->prompt_buffer); + c->flags |= CLIENT_STATUS; + break; + case KEYC_DOWN: + xfree(c->prompt_buffer); + + if (c->prompt_hindex != 0) { + c->prompt_hindex--; + c->prompt_buffer = xstrdup(ARRAY_ITEM( + &c->prompt_hdata, ARRAY_LENGTH( + &c->prompt_hdata) - 1 - c->prompt_hindex)); + } else + c->prompt_buffer = xstrdup(""); + + c->prompt_index = strlen(c->prompt_buffer); + c->flags |= CLIENT_STATUS; + break; case '\r': /* enter */ if (*c->prompt_buffer != '\0') { + status_prompt_add_history(c); + c->prompt_callback(c->prompt_data, c->prompt_buffer); server_clear_client_prompt(c); break; @@ -560,3 +591,19 @@ status_prompt_key(struct client *c, int key) break; } } + +/* Add line to the history. */ +void +status_prompt_add_history(struct client *c) +{ + if (ARRAY_LENGTH(&c->prompt_hdata) > 0 && + strcmp(ARRAY_LAST(&c->prompt_hdata), c->prompt_buffer) == 0) + return; + + if (ARRAY_LENGTH(&c->prompt_hdata) == PROMPT_HISTORY) { + xfree(ARRAY_FIRST(&c->prompt_hdata)); + ARRAY_REMOVE(&c->prompt_hdata, 0); + } + + ARRAY_ADD(&c->prompt_hdata, xstrdup(c->prompt_buffer)); +} |