diff options
author | Steve Bennett <steveb@workware.net.au> | 2021-01-21 07:14:17 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2021-01-23 12:49:12 +1000 |
commit | 43e71ad476f4c96815baf973f27e4c8006ebb33f (patch) | |
tree | 04fc8a0ed069e86c2c721a0580e240024215aa33 /jim-history.c | |
parent | 8f3e1ce80995c42a200db98fbfe02e4a60771c26 (diff) | |
download | jimtcl-43e71ad476f4c96815baf973f27e4c8006ebb33f.zip jimtcl-43e71ad476f4c96815baf973f27e4c8006ebb33f.tar.gz jimtcl-43e71ad476f4c96815baf973f27e4c8006ebb33f.tar.bz2 |
history: Add support for history keep
Fixes #191
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Reported-by: D. Bohdan <dbohdan@dbohdan.com>
Diffstat (limited to 'jim-history.c')
-rw-r--r-- | jim-history.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/jim-history.c b/jim-history.c index 7b00b2f..e1cc1d4 100644 --- a/jim-history.c +++ b/jim-history.c @@ -65,13 +65,28 @@ static int history_cmd_show(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } +static int history_cmd_keep(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + long len; + if (argc == 1) { + if (Jim_GetLong(interp, argv[0], &len) != JIM_OK) { + return JIM_ERR; + } + Jim_HistorySetMaxLen(len); + } + else { + Jim_SetResultInt(interp, Jim_HistoryGetMaxLen()); + } + return JIM_OK; +} + static const jim_subcmd_type history_command_table[] = { - { "getline", - "prompt ?varname?", - history_cmd_getline, + { "add", + "line", + history_cmd_add, 1, - 2, - /* Description: Reads one line from the user. Similar to gets. */ + 1, + /* Description: Adds the line to the history ands saves */ }, { "completion", "command", @@ -80,6 +95,20 @@ static const jim_subcmd_type history_command_table[] = { 1, /* Description: Sets an autocompletion callback command, or none if "" */ }, + { "getline", + "prompt ?varname?", + history_cmd_getline, + 1, + 2, + /* Description: Reads one line from the user. Similar to gets. */ + }, + { "keep", + "?count?", + history_cmd_keep, + 0, + 1, + /* Description: Set or display the max history length */ + }, { "load", "filename", history_cmd_load, @@ -94,13 +123,6 @@ static const jim_subcmd_type history_command_table[] = { 1, /* Description: Saves history to the given file */ }, - { "add", - "line", - history_cmd_add, - 1, - 1, - /* Description: Adds the line to the history ands saves */ - }, { "show", NULL, history_cmd_show, |