From d11db9738f88ec55d84ff2838938f00af2049149 Mon Sep 17 00:00:00 2001 From: Indra Date: Thu, 4 Oct 2018 15:42:45 +0200 Subject: [PATCH] added command history --- main_windows.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/main_windows.go b/main_windows.go index d682fa3..72c8276 100644 --- a/main_windows.go +++ b/main_windows.go @@ -27,6 +27,9 @@ var ( dlg *mainDialog dlgOriginalTitle string + + history []string + historyIndex = 0 ) func init() { @@ -124,10 +127,35 @@ func runGraphicalUi() (err error) { // Handle input dlg.ui.rconInput.KeyPress().Attach(func(key walk.Key) { + // handle history (arrow up/down) + if key == walk.KeyUp || key == walk.KeyDown { + if len(history) == 0 { + return + } + + if key == walk.KeyUp { + if historyIndex == 0 { + return + } + + historyIndex -= 1 + dlg.ui.rconInput.SetText(history[historyIndex]) + }else{ + if (historyIndex + 1) >= len(history) { + return + } + + historyIndex += 1 + dlg.ui.rconInput.SetText(history[historyIndex]) + } + + return + } + if key != walk.KeyReturn { return } - + if address == nil { uiLogError("No server configured.") return @@ -138,6 +166,10 @@ func runGraphicalUi() (err error) { uiLog(address.String() + "> " + cmd) sendRcon(cmd) + + // add to history + history = append(history, cmd) + historyIndex = len(history) }) // When window is initialized we can let a secondary routine print all