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

+13 -4
View File
@@ -128,7 +128,7 @@ func TestRuneSliceWidthLastRange(t *testing.T) {
}
}
func TestEscape(t *testing.T) {
func TestCmdEscape(t *testing.T) {
tests := []struct {
s string
exp string
@@ -147,13 +147,13 @@ func TestEscape(t *testing.T) {
}
for _, test := range tests {
if got := escape(test.s); !reflect.DeepEqual(got, test.exp) {
if got := cmdEscape(test.s); !reflect.DeepEqual(got, test.exp) {
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
}
}
}
func TestUnescape(t *testing.T) {
func TestCmdUnescape(t *testing.T) {
tests := []struct {
s string
exp string
@@ -172,7 +172,7 @@ func TestUnescape(t *testing.T) {
}
for _, test := range tests {
if got := unescape(test.s); !reflect.DeepEqual(got, test.exp) {
if got := cmdUnescape(test.s); !reflect.DeepEqual(got, test.exp) {
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
}
}
@@ -185,8 +185,17 @@ func TestTokenize(t *testing.T) {
}{
{"", []string{""}},
{"foo", []string{"foo"}},
{`foo\`, []string{`foo\`}},
{`foo"`, []string{`foo"`}},
{"foo bar", []string{"foo", "bar"}},
{`foo\ bar`, []string{`foo\ bar`}},
{`"foo bar"`, []string{`"foo bar"`}},
{`"foo" "bar"`, []string{`"foo"`, `"bar"`}},
{`"foo "bar"`, []string{`"foo "bar"`}},
{`"foo\" bar"`, []string{`"foo\" bar"`}},
{`\"foo bar\"`, []string{`\"foo`, `bar\"`}},
{`:rename foo\ bar`, []string{":rename", `foo\ bar`}},
{`!dir "C:\Program Files"`, []string{"!dir", `"C:\Program Files"`}},
}
for _, test := range tests {