diff --git a/app.go b/app.go index 3c1d508..0dd2e84 100644 --- a/app.go +++ b/app.go @@ -9,10 +9,17 @@ import ( "strings" ) +type cmdItem struct { + pref string + s string +} + type app struct { - ui *ui - nav *nav - quit chan bool + ui *ui + nav *nav + quit chan bool + cmdHist []cmdItem + cmdHind int } func newApp() *app { diff --git a/doc.go b/doc.go index 4efad37..48f7281 100644 --- a/doc.go +++ b/doc.go @@ -52,6 +52,8 @@ keybindings: cmd-escape (default "") cmd-comp (default "") cmd-enter (default "" and "") + cmd-hist-next (default "") + cmd-hist-prev (default "") cmd-delete (default "" and "") cmd-delete-back (default "" and "") cmd-left (default "" and "") diff --git a/docstring.go b/docstring.go index 4fb6725..bc95425 100644 --- a/docstring.go +++ b/docstring.go @@ -56,6 +56,8 @@ keybindings: cmd-escape (default "") cmd-comp (default "") cmd-enter (default "" and "") + cmd-hist-next (default "") + cmd-hist-prev (default "") cmd-delete (default "" and "") cmd-delete-back (default "" and "") cmd-left (default "" and "") diff --git a/eval.go b/eval.go index 60d4c95..d492405 100644 --- a/eval.go +++ b/eval.go @@ -395,7 +395,6 @@ func (e *callExpr) eval(app *app, args []string) { } case "cmd-escape": app.ui.menubuf = nil - app.ui.cmdbuf = nil app.ui.cmdlacc = nil app.ui.cmdracc = nil app.ui.cmdpref = "" @@ -418,7 +417,6 @@ func (e *callExpr) eval(app *app, args []string) { return } app.ui.menubuf = nil - app.ui.cmdbuf = nil app.ui.cmdlacc = nil app.ui.cmdracc = nil switch app.ui.cmdpref { @@ -456,7 +454,34 @@ func (e *callExpr) eval(app *app, args []string) { default: log.Printf("entering unknown execution prefix: %q", app.ui.cmdpref) } + app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdpref, s}) app.ui.cmdpref = "" + case "cmd-hist-prev": + if app.cmdHind == len(app.cmdHist) { + return + } + app.cmdHind++ + cmd := app.cmdHist[len(app.cmdHist)-app.cmdHind] + app.ui.cmdpref = cmd.pref + app.ui.cmdlacc = []rune(cmd.s) + app.ui.cmdracc = nil + app.ui.menubuf = nil + case "cmd-hist-next": + if app.cmdHind > 0 { + app.cmdHind-- + } + if app.cmdHind == 0 { + app.ui.menubuf = nil + app.ui.cmdlacc = nil + app.ui.cmdracc = nil + app.ui.cmdpref = "" + return + } + cmd := app.cmdHist[len(app.cmdHist)-app.cmdHind] + app.ui.cmdpref = cmd.pref + app.ui.cmdlacc = []rune(cmd.s) + app.ui.cmdracc = nil + app.ui.menubuf = nil case "cmd-delete-back": if len(app.ui.cmdlacc) > 0 { app.ui.cmdlacc = app.ui.cmdlacc[:len(app.ui.cmdlacc)-1] diff --git a/opts.go b/opts.go index afa7998..8c08e57 100644 --- a/opts.go +++ b/opts.go @@ -59,6 +59,8 @@ func init() { gOpts.keys["$"] = &callExpr{"read-shell", nil} gOpts.keys["!"] = &callExpr{"read-shell-wait", nil} gOpts.keys["&"] = &callExpr{"read-shell-async", nil} + gOpts.keys[""] = &callExpr{"cmd-hist-next", nil} + gOpts.keys[""] = &callExpr{"cmd-hist-prev", nil} gOpts.keys["/"] = &callExpr{"search", nil} gOpts.keys["?"] = &callExpr{"search-back", nil} gOpts.keys["n"] = &callExpr{"search-next", nil} @@ -79,6 +81,8 @@ func init() { gOpts.cmdkeys[""] = &callExpr{"cmd-comp", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-enter", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-enter", nil} + gOpts.cmdkeys[""] = &callExpr{"cmd-hist-next", nil} + gOpts.cmdkeys[""] = &callExpr{"cmd-hist-prev", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-delete-back", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-delete-back", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-delete", nil}