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:
Joe Lim authored and GitHub committed 2025-08-07 15:14:25 +10:00
1 parent 88a599643d
commit 42b36fd52c
10 files changed
+444 -341

No files matched your search

+7 -7
View File
@@ -658,7 +658,6 @@ type ui struct {
cmdAccLeft []rune
cmdAccRight []rune
cmdYankBuf []rune
cmdTmp []rune
keyAcc []rune
keyCount []rune
styles styleMap
@@ -1668,7 +1667,7 @@ func anyKey() {
os.Stdin.Read(b)
}
func listMatches(screen tcell.Screen, matches []string, selectedInd int) string {
func listMatches(screen tcell.Screen, matches []compMatch, selectedInd int) string {
mlen := len(matches)
if mlen < 2 {
return ""
@@ -1679,7 +1678,7 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) string
wtot, _ := screen.Size()
wcol := 0
for _, m := range matches {
wcol = max(wcol, len(m))
wcol = max(wcol, runeSliceWidth([]rune(m.name)))
}
wcol += gOpts.tabstop - wcol%gOpts.tabstop
ncol := max(wtot/wcol, 1)
@@ -1688,12 +1687,13 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) string
for i := 0; i < mlen; {
for j := 0; j < ncol && i < mlen; i, j = i+1, j+1 {
target := matches[i]
name := matches[i].name
w := runeSliceWidth([]rune(name))
if selectedInd == i {
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
if i == selectedInd {
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", name, wcol-w, "")
} else {
fmt.Fprintf(&b, "%s%*s", target, wcol-len(target), "")
fmt.Fprintf(&b, "%s%*s", name, wcol-w, "")
}
}
b.WriteByte('\n')