* utility modulus function * ui adapt for tab menu cycle * refactor(listMatches) for tab menu cycle * refactor(draw) handle tab menu selection highlight * refactor(eval) cmd-complete cycle + reset handles * feat: added backtab counter-cycle in the completition menu * cleanup * docs changes * refactor: make tab cycle own commands * docs: tab cycle documentation * bug: the matches list was not complete because index +2 after row end * refactor(tab cycle): handle the complete menu command print * refactor(tab cycle): make the cmdTmp varibale mymic cmdAccLeft + check for partial commands * refactor(tab cycle): fix how to handle the menu completiton from different events * fix(tab cycle): fix cmd-complete so that it works with new tab cycle commands * style: changed puprle to reverse * cleaned up cycle logic + reverted listMatches * cleaned up eval logic for cycle feat. * cleanup Co-authored-by: 2pac <tarasyarema@pm.me>
This commit is contained in:
1 parent
228a20ffd1
commit
17ed724e67
5 files changed
+275
-41
No files matched your search
@@ -372,6 +372,10 @@ func splitKeys(s string) (keys []string) {
|
||||
}
|
||||
|
||||
func update(app *app) {
|
||||
// Remove the current menu buffer
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
|
||||
switch {
|
||||
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
||||
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||
@@ -406,8 +410,11 @@ func update(app *app) {
|
||||
|
||||
func normal(app *app) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdTmp = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
}
|
||||
|
||||
@@ -1019,6 +1026,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if len(e.args) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Reset the completition menu as in bash/vim
|
||||
// and update the pertinent variables
|
||||
if app.ui.menuBuf != nil {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
}
|
||||
|
||||
insert(app, e.args[0])
|
||||
case "cmd-escape":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
@@ -1045,20 +1060,120 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
|
||||
// If there are no multiple matches
|
||||
// we do not need to show the list of matches
|
||||
if len(matches) <= 1 {
|
||||
app.ui.menuBuf = nil
|
||||
return
|
||||
}
|
||||
|
||||
if b, err := listMatches(app.ui.screen, matches); err != nil {
|
||||
app.ui.echoerrf("cmd-complete: %s", err)
|
||||
} else {
|
||||
app.ui.menuBuf = b
|
||||
}
|
||||
case "cmd-menu-complete":
|
||||
var target []rune
|
||||
|
||||
// target will store the current menu query
|
||||
// note that, as we will store the current selected value
|
||||
// in cmdAccLeft, we can not call the complete function with its
|
||||
// value, as it is already a final completition result
|
||||
if app.ui.menuBuf == nil {
|
||||
target = app.ui.cmdAccLeft
|
||||
app.ui.cmdTmp = app.ui.cmdAccLeft
|
||||
} else {
|
||||
target = app.ui.cmdTmp
|
||||
}
|
||||
|
||||
var matches []string
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, app.ui.cmdAccLeft = completeCmd(target)
|
||||
case "/", "?":
|
||||
matches, app.ui.cmdAccLeft = completeFile(target)
|
||||
case "$", "%", "!", "&":
|
||||
matches, app.ui.cmdAccLeft = completeShell(target)
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
|
||||
if len(matches) > 1 {
|
||||
app.ui.menuBuf = listMatches(app.ui.screen, matches)
|
||||
step := 1
|
||||
|
||||
// Check if the tab-selecttion was inited
|
||||
if app.ui.menuSelected == -2 {
|
||||
app.ui.menuSelected = -1
|
||||
} else {
|
||||
app.ui.menuSelected = mod(app.ui.menuSelected+step, len(matches))
|
||||
}
|
||||
|
||||
if err := listMatchesMenu(app.ui, matches); err != nil {
|
||||
app.ui.echoerrf("cmd-menu-complete: %s", err)
|
||||
}
|
||||
} else {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
}
|
||||
case "cmd-menu-complete-back":
|
||||
var target []rune
|
||||
|
||||
if app.ui.menuBuf == nil {
|
||||
target = app.ui.cmdAccLeft
|
||||
app.ui.cmdTmp = app.ui.cmdAccLeft
|
||||
} else {
|
||||
target = app.ui.cmdTmp
|
||||
}
|
||||
|
||||
var matches []string
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, app.ui.cmdAccLeft = completeCmd(target)
|
||||
case "/", "?":
|
||||
matches, app.ui.cmdAccLeft = completeFile(target)
|
||||
case "$", "%", "!", "&":
|
||||
matches, app.ui.cmdAccLeft = completeShell(target)
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
|
||||
if len(matches) > 1 {
|
||||
step := -1
|
||||
|
||||
// Check if the tab-selecttion was inited
|
||||
if app.ui.menuSelected == -2 {
|
||||
app.ui.menuSelected = -1
|
||||
} else {
|
||||
app.ui.menuSelected = mod(app.ui.menuSelected+step, len(matches))
|
||||
}
|
||||
|
||||
if err := listMatchesMenu(app.ui, matches); err != nil {
|
||||
app.ui.echoerrf("cmd-menu-complete-back: %s", err)
|
||||
}
|
||||
} else {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
}
|
||||
case "cmd-enter":
|
||||
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
|
||||
if len(s) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdTmp = nil
|
||||
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
log.Printf("command: %s", s)
|
||||
@@ -1190,8 +1305,10 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
if app.cmdHistoryInd == 0 {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdTmp = nil
|
||||
app.ui.cmdPrefix = ":"
|
||||
return
|
||||
}
|
||||
@@ -1199,7 +1316,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = cmd.prefix
|
||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdTmp = nil
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
case "cmd-history-prev":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
@@ -1215,7 +1334,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = cmd.prefix
|
||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdTmp = nil
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.menuSelected = -2
|
||||
case "cmd-delete":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user