Improvements for command line completion (#2071)
- Refactor of the completion module, primarily to have the `match...` functions return the result for each possible match, so that they can be displayed when the user cycles through the completions using `cmd-menu-complete`/`cmd-menu-complete-back` - Add support for completing list options (e.g. `set info user:group:size:time`) - Provide different implementations for escaping/unescaping for `lfrc` command syntax, Unix and Windows. It is a bit hacky, but for now I want to keep `lf` as shell-agnostic as possible which means minimizing the logic based on `gOpts.shell` - Fix alignment bug in the completion menu when displaying filenames with fullwidth characters
This commit is contained in:
1 parent
88a599643d
commit
42b36fd52c
10 files changed
+444
-341
No files matched your search
@@ -701,54 +701,6 @@ func splitKeys(s string) (keys []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func doComplete(app *app) (matches []string) {
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||
case "/", "?":
|
||||
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
||||
case "$", "%", "!", "&":
|
||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func menuComplete(app *app, dir int) {
|
||||
if !app.menuCompActive {
|
||||
toks := tokenize(string(app.ui.cmdAccLeft))
|
||||
for i, tok := range toks {
|
||||
toks[i] = replaceTilde(tok)
|
||||
}
|
||||
app.ui.cmdAccLeft = []rune(strings.Join(toks, " "))
|
||||
app.ui.cmdTmp = app.ui.cmdAccLeft
|
||||
app.menuComps = doComplete(app)
|
||||
if len(app.menuComps) > 1 {
|
||||
app.menuCompInd = -1
|
||||
app.menuCompActive = true
|
||||
}
|
||||
} else {
|
||||
app.menuCompInd += dir
|
||||
if app.menuCompInd == len(app.menuComps) {
|
||||
app.menuCompInd = 0
|
||||
} else if app.menuCompInd < 0 {
|
||||
app.menuCompInd = len(app.menuComps) - 1
|
||||
}
|
||||
|
||||
comp := app.menuComps[app.menuCompInd]
|
||||
toks := tokenize(string(app.ui.cmdTmp))
|
||||
last := toks[len(toks)-1]
|
||||
|
||||
if app.ui.cmdPrefix != "/" && app.ui.cmdPrefix != "?" {
|
||||
comp = escape(comp)
|
||||
_, last = filepath.Split(last)
|
||||
}
|
||||
|
||||
ind := len(app.ui.cmdTmp) - len([]rune(last))
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdTmp[:ind], []rune(comp)...)
|
||||
}
|
||||
app.ui.menu = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
|
||||
}
|
||||
|
||||
func update(app *app) {
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
@@ -1990,12 +1942,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
normal(app)
|
||||
case "cmd-complete":
|
||||
matches := doComplete(app)
|
||||
app.ui.menu = listMatches(app.ui.screen, matches, -1)
|
||||
app.doComplete()
|
||||
case "cmd-menu-complete":
|
||||
menuComplete(app, 1)
|
||||
app.menuComplete(1)
|
||||
case "cmd-menu-complete-back":
|
||||
menuComplete(app, -1)
|
||||
app.menuComplete(-1)
|
||||
case "cmd-menu-accept":
|
||||
app.ui.menu = ""
|
||||
app.menuCompActive = false
|
||||
|
||||
Reference in new issue
Block a user