From 1caf38e89834e23138a4543aa17b84b5966fb2d7 Mon Sep 17 00:00:00 2001 From: Ronald Reagan Date: Thu, 23 Jan 2014 12:09:05 -0800 Subject: [PATCH] Added command line history. New file 'history' used in the config folder --- changelog.txt | 17 ++++++++++++++++- source/src/console.cpp | 19 +++++++++++++++++++ source/src/console.h | 2 ++ source/src/main.cpp | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index dce7bc39..8209fa61 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,19 @@ -AssaultCube ChangeLog +AssaultCube ChangeLog + +1.2.0.2 -> 1. +--------------------- + +Features +--------------------- + +[*] Added command line history + + +Misc +--------------------- + +[*] Removed cubescript lasttarget + 1.2.0.1 -> 1.2.0.2 --------------------- diff --git a/source/src/console.cpp b/source/src/console.cpp index 9312e8a7..eee89a7a 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -475,6 +475,25 @@ void history_(int *n) COMMANDN(history, history_, "i"); +void savehistory() { + stream *f = openfile(path("config/history", true), "w"); + if(!f) return; + loopv(history) { + f->printf("%s\n",history[i]->buf); + } +} + +void loadhistory() { + char *histbuf = loadfile(path("config/history", true),NULL); + char *line = NULL; + line = strtok(histbuf, "\n"); + while (line) { + history.add(new hline)->buf = line; + line = strtok(NULL, "\n"); + } + histpos = history.length(); +} + void execbind(keym &k, bool isdown) { loopv(releaseactions) diff --git a/source/src/console.h b/source/src/console.h index 1e5add1d..274ac6d0 100644 --- a/source/src/console.h +++ b/source/src/console.h @@ -258,3 +258,5 @@ struct textinputbuffer_wip } }; +void savehistory(); +void loadhistory(); diff --git a/source/src/main.cpp b/source/src/main.cpp index 69893599..1f486964 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -37,6 +37,7 @@ void quit() // normal exit writepcksourcecfg(); if(resetcfg) deletecfg(); else writecfg(); + savehistory(); cleanup(NULL); popscontext(); exit(EXIT_SUCCESS); @@ -1168,6 +1169,7 @@ int main(int argc, char **argv) exec("config/securemaps.cfg"); exec("config/admin.cfg"); execfile("config/servers.cfg"); + loadhistory(); per_idents = true; static char resdata[] = { 112, 97, 99, 107, 97, 103, 101, 115, 47, 116, 101, 120, 116, 117, 114, 101, 115, 47, 107, 117, 114, 116, 47, 107, 108, 105, 116, 101, 50, 46, 106, 112, 103, 0 };