diff options
author | Galen Abell <galen@galenabell.com> | 2019-07-23 12:52:33 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-26 14:29:34 -0400 |
commit | 8635c70fda20b91f97c42f4e23e97bc01a14a89d (patch) | |
tree | ea70a40f7617782ca28060965ad253fa0e686161 /widgets/exline.go | |
parent | 67fb0938a66605a0b6a837005804637b348b250d (diff) | |
download | aerc-8635c70fda20b91f97c42f4e23e97bc01a14a89d.tar.gz |
Add command history and cycling
Aerc will keep track of the previous 1000 commands, which the user can cycle through using the arrow keys while in the ex-line. Pressing up will move backwards in history while pressing down will move forward.
Diffstat (limited to 'widgets/exline.go')
-rw-r--r-- | widgets/exline.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/widgets/exline.go b/widgets/exline.go index e984ee1..b7b4e3d 100644 --- a/widgets/exline.go +++ b/widgets/exline.go @@ -3,6 +3,7 @@ package widgets import ( "github.com/gdamore/tcell" + "git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/lib/ui" ) @@ -11,17 +12,20 @@ type ExLine struct { cancel func() commit func(cmd string) tabcomplete func(cmd string) []string + cmdHistory lib.History input *ui.TextInput } func NewExLine(commit func(cmd string), cancel func(), - tabcomplete func(cmd string) []string) *ExLine { + tabcomplete func(cmd string) []string, + cmdHistory lib.History) *ExLine { input := ui.NewTextInput("").Prompt(":") exline := &ExLine{ cancel: cancel, commit: commit, tabcomplete: tabcomplete, + cmdHistory: cmdHistory, input: input, } input.OnInvalidate(func(d ui.Drawable) { @@ -47,10 +51,18 @@ func (ex *ExLine) Event(event tcell.Event) bool { case *tcell.EventKey: switch event.Key() { case tcell.KeyEnter: + cmd := ex.input.String() ex.input.Focus(false) - ex.commit(ex.input.String()) + ex.commit(cmd) + case tcell.KeyUp: + ex.input.Set(ex.cmdHistory.Prev()) + ex.Invalidate() + case tcell.KeyDown: + ex.input.Set(ex.cmdHistory.Next()) + ex.Invalidate() case tcell.KeyEsc, tcell.KeyCtrlC: ex.input.Focus(false) + ex.cmdHistory.Reset() ex.cancel() case tcell.KeyTab: complete := ex.tabcomplete(ex.input.StringLeft()) |