parent
33c55f0f51
commit
9962b378a8
7
app.go
7
app.go
@ -9,10 +9,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type cmdItem struct {
|
||||||
|
pref string
|
||||||
|
s string
|
||||||
|
}
|
||||||
|
|
||||||
type app struct {
|
type app struct {
|
||||||
ui *ui
|
ui *ui
|
||||||
nav *nav
|
nav *nav
|
||||||
quit chan bool
|
quit chan bool
|
||||||
|
cmdHist []cmdItem
|
||||||
|
cmdHind int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApp() *app {
|
func newApp() *app {
|
||||||
|
2
doc.go
2
doc.go
@ -52,6 +52,8 @@ keybindings:
|
|||||||
cmd-escape (default "<esc>")
|
cmd-escape (default "<esc>")
|
||||||
cmd-comp (default "<tab>")
|
cmd-comp (default "<tab>")
|
||||||
cmd-enter (default "<c-j>" and "<enter>")
|
cmd-enter (default "<c-j>" and "<enter>")
|
||||||
|
cmd-hist-next (default "<c-n>")
|
||||||
|
cmd-hist-prev (default "<c-p>")
|
||||||
cmd-delete (default "<c-d>" and "<delete>")
|
cmd-delete (default "<c-d>" and "<delete>")
|
||||||
cmd-delete-back (default "<bs>" and "<bs2>")
|
cmd-delete-back (default "<bs>" and "<bs2>")
|
||||||
cmd-left (default "<c-b>" and "<left>")
|
cmd-left (default "<c-b>" and "<left>")
|
||||||
|
@ -56,6 +56,8 @@ keybindings:
|
|||||||
cmd-escape (default "<esc>")
|
cmd-escape (default "<esc>")
|
||||||
cmd-comp (default "<tab>")
|
cmd-comp (default "<tab>")
|
||||||
cmd-enter (default "<c-j>" and "<enter>")
|
cmd-enter (default "<c-j>" and "<enter>")
|
||||||
|
cmd-hist-next (default "<c-n>")
|
||||||
|
cmd-hist-prev (default "<c-p>")
|
||||||
cmd-delete (default "<c-d>" and "<delete>")
|
cmd-delete (default "<c-d>" and "<delete>")
|
||||||
cmd-delete-back (default "<bs>" and "<bs2>")
|
cmd-delete-back (default "<bs>" and "<bs2>")
|
||||||
cmd-left (default "<c-b>" and "<left>")
|
cmd-left (default "<c-b>" and "<left>")
|
||||||
|
29
eval.go
29
eval.go
@ -395,7 +395,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
app.ui.menubuf = nil
|
app.ui.menubuf = nil
|
||||||
app.ui.cmdbuf = nil
|
|
||||||
app.ui.cmdlacc = nil
|
app.ui.cmdlacc = nil
|
||||||
app.ui.cmdracc = nil
|
app.ui.cmdracc = nil
|
||||||
app.ui.cmdpref = ""
|
app.ui.cmdpref = ""
|
||||||
@ -418,7 +417,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.menubuf = nil
|
app.ui.menubuf = nil
|
||||||
app.ui.cmdbuf = nil
|
|
||||||
app.ui.cmdlacc = nil
|
app.ui.cmdlacc = nil
|
||||||
app.ui.cmdracc = nil
|
app.ui.cmdracc = nil
|
||||||
switch app.ui.cmdpref {
|
switch app.ui.cmdpref {
|
||||||
@ -456,7 +454,34 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
default:
|
default:
|
||||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdpref)
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdpref)
|
||||||
}
|
}
|
||||||
|
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdpref, s})
|
||||||
app.ui.cmdpref = ""
|
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":
|
case "cmd-delete-back":
|
||||||
if len(app.ui.cmdlacc) > 0 {
|
if len(app.ui.cmdlacc) > 0 {
|
||||||
app.ui.cmdlacc = app.ui.cmdlacc[:len(app.ui.cmdlacc)-1]
|
app.ui.cmdlacc = app.ui.cmdlacc[:len(app.ui.cmdlacc)-1]
|
||||||
|
4
opts.go
4
opts.go
@ -59,6 +59,8 @@ func init() {
|
|||||||
gOpts.keys["$"] = &callExpr{"read-shell", nil}
|
gOpts.keys["$"] = &callExpr{"read-shell", nil}
|
||||||
gOpts.keys["!"] = &callExpr{"read-shell-wait", nil}
|
gOpts.keys["!"] = &callExpr{"read-shell-wait", nil}
|
||||||
gOpts.keys["&"] = &callExpr{"read-shell-async", nil}
|
gOpts.keys["&"] = &callExpr{"read-shell-async", nil}
|
||||||
|
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
||||||
|
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
||||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
gOpts.keys["/"] = &callExpr{"search", nil}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
||||||
@ -79,6 +81,8 @@ func init() {
|
|||||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil}
|
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil}
|
||||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil}
|
||||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil}
|
||||||
|
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
||||||
|
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
||||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil}
|
||||||
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil}
|
||||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil}
|
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil}
|
||||||
|
Loading…
Reference in New Issue
Block a user