Skip to content

Commit

Permalink
added history limit and fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Oct 4, 2018
1 parent d11db97 commit cb9facd
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ var (

dlg *mainDialog
dlgOriginalTitle string
history []string

history []string
historyIndex = 0
)

Expand Down Expand Up @@ -74,6 +74,16 @@ func uiUpdateAddress() {
}
}

func addToHistory(command string) {
// limit history to 20 items
if len(history) > 20 {
history = append(history[:0], history[0+1:]...)
}

history = append(history, command)
historyIndex = len(history)
}

func runGraphicalUi() (err error) {
dlg = new(mainDialog)
if err := dlg.init(); err != nil {
Expand Down Expand Up @@ -132,30 +142,30 @@ func runGraphicalUi() (err error) {
if len(history) == 0 {
return
}

if key == walk.KeyUp {
if historyIndex == 0 {
if historyIndex == 0 {
return
}

historyIndex -= 1
dlg.ui.rconInput.SetText(history[historyIndex])
}else{
} 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
Expand All @@ -166,10 +176,9 @@ func runGraphicalUi() (err error) {

uiLog(address.String() + "> " + cmd)
sendRcon(cmd)

// add to history
history = append(history, cmd)
historyIndex = len(history)
addToHistory(cmd)
})

// When window is initialized we can let a secondary routine print all
Expand Down

0 comments on commit cb9facd

Please sign in to comment.