cleanup
This commit is contained in:
1 parent
e532db082f
commit
a717c31ca1
12 files changed
+304
-305
No files matched your search
@@ -58,7 +58,7 @@ func waitKey() error {
|
||||
func (app *app) handleInp() {
|
||||
clientChan := app.ui.readExpr()
|
||||
|
||||
var serverChan chan expr
|
||||
var serverChan <-chan expr
|
||||
|
||||
c, err := net.Dial("unix", gSocketPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -64,7 +64,7 @@ func client() {
|
||||
app.handleInp()
|
||||
}
|
||||
|
||||
func readExpr(c net.Conn) chan expr {
|
||||
func readExpr(c net.Conn) <-chan expr {
|
||||
ch := make(chan expr)
|
||||
|
||||
go func() {
|
||||
|
||||
@@ -206,7 +206,7 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
switch len(f) {
|
||||
case 1:
|
||||
words := gCmdWords
|
||||
for c, _ := range gOpts.cmds {
|
||||
for c := range gOpts.cmds {
|
||||
words = append(words, c)
|
||||
}
|
||||
sort.Strings(words)
|
||||
|
||||
+5
-5
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
func TestMatchLongest(t *testing.T) {
|
||||
tests := []struct {
|
||||
fst string
|
||||
snd string
|
||||
res string
|
||||
s1 string
|
||||
s2 string
|
||||
exp string
|
||||
}{
|
||||
{"", "", ""},
|
||||
{"", "foo", ""},
|
||||
@@ -21,8 +21,8 @@ func TestMatchLongest(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if l := matchLongest(test.fst, test.snd); l != test.res {
|
||||
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.fst, test.snd, test.res, l)
|
||||
if got := matchLongest(test.s1, test.s2); got != test.exp {
|
||||
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,15 +188,24 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "open":
|
||||
err := app.nav.open()
|
||||
if err == nil {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("opening: %s", err)
|
||||
app.ui.message = msg
|
||||
log.Print(msg)
|
||||
return
|
||||
}
|
||||
if err != errNotDir {
|
||||
app.ui.message = err.Error()
|
||||
log.Print(err)
|
||||
|
||||
if curr.IsDir() {
|
||||
app.nav.open()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("opening directory: %s", err)
|
||||
app.ui.message = msg
|
||||
log.Print(msg)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+42
-42
@@ -6,10 +6,10 @@ import (
|
||||
)
|
||||
|
||||
// These inputs are used in scan and parse tests.
|
||||
var gTests = []struct {
|
||||
var gEvalTests = []struct {
|
||||
inp string
|
||||
toks []string
|
||||
exprs []Expr
|
||||
exprs []expr
|
||||
}{
|
||||
{
|
||||
"",
|
||||
@@ -26,217 +26,217 @@ var gTests = []struct {
|
||||
{
|
||||
"echo hello",
|
||||
[]string{"echo", "hello", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo hello world",
|
||||
[]string{"echo", "hello", "world", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello", "world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello", "world"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo 'hello world'",
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
[]string{"echo", "hello\tworld", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo hello\\\nworld",
|
||||
[]string{"echo", "hello\nworld", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\aworld`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]Expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"set hidden # trailing comments are allowed",
|
||||
[]string{"set", "hidden", "\n"},
|
||||
[]Expr{&setExpr{"hidden", ""}},
|
||||
[]expr{&setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"set hidden; set preview",
|
||||
[]string{"set", "hidden", ";", "set", "preview", "\n"},
|
||||
[]Expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"set hidden\nset preview",
|
||||
[]string{"set", "hidden", "\n", "set", "preview", "\n"},
|
||||
[]Expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"set ratios 1:2:3",
|
||||
[]string{"set", "ratios", "1:2:3", "\n"},
|
||||
[]Expr{&setExpr{"ratios", "1:2:3"}},
|
||||
[]expr{&setExpr{"ratios", "1:2:3"}},
|
||||
},
|
||||
|
||||
{
|
||||
"set ratios 1:2:3;",
|
||||
[]string{"set", "ratios", "1:2:3", ";"},
|
||||
[]Expr{&setExpr{"ratios", "1:2:3"}},
|
||||
[]expr{&setExpr{"ratios", "1:2:3"}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3",
|
||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n"},
|
||||
[]Expr{&listExpr{[]Expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3\nset hidden",
|
||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
|
||||
[]Expr{&listExpr{[]Expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3;",
|
||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n"},
|
||||
[]Expr{&listExpr{[]Expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3;\nset hidden",
|
||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
|
||||
[]Expr{&listExpr{[]Expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh cd ~",
|
||||
[]string{"map", "gh", "cd", "~", "\n"},
|
||||
[]Expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh cd ~;",
|
||||
[]string{"map", "gh", "cd", "~", ";"},
|
||||
[]Expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh :cd ~",
|
||||
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
||||
[]Expr{&mapExpr{"gh", &listExpr{[]Expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh :cd ~;",
|
||||
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
||||
[]Expr{&mapExpr{"gh", &listExpr{[]Expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"cmd usage $du -h . | less",
|
||||
[]string{"cmd", "usage", "$", "du -h . | less", "\n"},
|
||||
[]Expr{&cmdExpr{"usage", &execExpr{"$", "du -h . | less"}}},
|
||||
[]expr{&cmdExpr{"usage", &execExpr{"$", "du -h . | less"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"cmd 世界 $echo 世界",
|
||||
[]string{"cmd", "世界", "$", "echo 世界", "\n"},
|
||||
[]Expr{&cmdExpr{"世界", &execExpr{"$", "echo 世界"}}},
|
||||
[]expr{&cmdExpr{"世界", &execExpr{"$", "echo 世界"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u usage",
|
||||
[]string{"map", "u", "usage", "\n"},
|
||||
[]Expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u usage;",
|
||||
[]string{"map", "u", "usage", ";"},
|
||||
[]Expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u :usage",
|
||||
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
||||
[]Expr{&mapExpr{"u", &listExpr{[]Expr{&callExpr{"usage", nil}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u :usage;",
|
||||
[]string{"map", "u", ":", "usage", ";", "\n"},
|
||||
[]Expr{&mapExpr{"u", &listExpr{[]Expr{&callExpr{"usage", nil}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space>",
|
||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||
[]Expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space>;",
|
||||
[]string{"map", "r", "push", ":rename<space>;", "\n"},
|
||||
[]Expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space> # trailing comments are allowed after a space",
|
||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||
[]Expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r :push :rename<space>",
|
||||
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
||||
[]Expr{&mapExpr{"r", &listExpr{[]Expr{&callExpr{"push", []string{":rename<space>"}}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r :push :rename<space> ; set hidden",
|
||||
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
||||
[]Expr{&mapExpr{"r", &listExpr{[]Expr{&callExpr{"push", []string{":rename<space>"}}, &setExpr{"hidden", ""}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}}, &setExpr{"hidden", ""}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u $du -h . | less",
|
||||
[]string{"map", "u", "$", "du -h . | less", "\n"},
|
||||
[]Expr{&mapExpr{"u", &execExpr{"$", "du -h . | less"}}},
|
||||
[]expr{&mapExpr{"u", &execExpr{"$", "du -h . | less"}}},
|
||||
},
|
||||
|
||||
{
|
||||
"cmd usage $du -h \"$1\" | less",
|
||||
[]string{"cmd", "usage", "$", `du -h "$1" | less`, "\n"},
|
||||
[]Expr{&cmdExpr{"usage", &execExpr{"$", `du -h "$1" | less`}}},
|
||||
[]expr{&cmdExpr{"usage", &execExpr{"$", `du -h "$1" | less`}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u usage /",
|
||||
[]string{"map", "u", "usage", "/", "\n"},
|
||||
[]Expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map ss :set sortby size; set showinfo size",
|
||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "showinfo", "size", "\n", "\n"},
|
||||
[]Expr{&mapExpr{"ss", &listExpr{[]Expr{&setExpr{"sortby", "size"}, &setExpr{"showinfo", "size"}}}}},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"showinfo", "size"}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map ss :set sortby size; set showinfo size;",
|
||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "showinfo", "size", ";", "\n"},
|
||||
[]Expr{&mapExpr{"ss", &listExpr{[]Expr{&setExpr{"sortby", "size"}, &setExpr{"showinfo", "size"}}}}},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"showinfo", "size"}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -248,7 +248,7 @@ var gTests = []struct {
|
||||
"cd", "~", "\n",
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]Expr{&cmdExpr{"gohome", &listExpr{[]Expr{
|
||||
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}},
|
||||
&setExpr{"hidden", ""}}},
|
||||
}},
|
||||
@@ -263,7 +263,7 @@ var gTests = []struct {
|
||||
"cd", "~", "\n",
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]Expr{&mapExpr{"gh", &listExpr{[]Expr{
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}},
|
||||
&setExpr{"hidden", ""}}},
|
||||
}},
|
||||
@@ -282,7 +282,7 @@ var gTests = []struct {
|
||||
tar -czvf "foo.tar.gz" foo
|
||||
rm -rf foo
|
||||
`, "}}", "\n"},
|
||||
[]Expr{&mapExpr{"c", &execExpr{"$", `
|
||||
[]expr{&mapExpr{"c", &execExpr{"$", `
|
||||
mkdir foo
|
||||
IFS=':'; cp ${fs} foo
|
||||
tar -czvf "foo.tar.gz" foo
|
||||
@@ -303,7 +303,7 @@ var gTests = []struct {
|
||||
tar -czvf "$1.tar.gz" "$1"
|
||||
rm -rf "$1"
|
||||
`, "}}", "\n"},
|
||||
[]Expr{&cmdExpr{"compress", &execExpr{"$", `
|
||||
[]expr{&cmdExpr{"compress", &execExpr{"$", `
|
||||
mkdir "$1"
|
||||
IFS=':'; cp ${fs} "$1"
|
||||
tar -czvf "$1.tar.gz" "$1"
|
||||
|
||||
+53
-53
@@ -28,9 +28,9 @@ func TestIsRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRuneWidth(t *testing.T) {
|
||||
chars := []struct {
|
||||
r rune
|
||||
w int
|
||||
tests := []struct {
|
||||
r rune
|
||||
exp int
|
||||
}{
|
||||
{' ', 1},
|
||||
{'a', 1},
|
||||
@@ -40,17 +40,17 @@ func TestRuneWidth(t *testing.T) {
|
||||
{'界', 2},
|
||||
}
|
||||
|
||||
for _, char := range chars {
|
||||
if w := runeWidth(char.r); w != char.w {
|
||||
t.Errorf("at input '%c' expected '%d' but got '%d'", char.r, char.w, w)
|
||||
for _, test := range tests {
|
||||
if got := runeWidth(test.r); got != test.exp {
|
||||
t.Errorf("at input '%c' expected '%d' but got '%d'", test.r, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuneSliceWidth(t *testing.T) {
|
||||
slices := []struct {
|
||||
s []rune
|
||||
w int
|
||||
tests := []struct {
|
||||
rs []rune
|
||||
exp int
|
||||
}{
|
||||
{[]rune{'a', 'b'}, 2},
|
||||
{[]rune{'ı', 'ş'}, 2},
|
||||
@@ -58,19 +58,19 @@ func TestRuneSliceWidth(t *testing.T) {
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 6},
|
||||
}
|
||||
|
||||
for _, slice := range slices {
|
||||
if w := runeSliceWidth(slice.s); w != slice.w {
|
||||
t.Errorf("at input '%v' expected '%d' but got '%d'", slice.s, slice.w, w)
|
||||
for _, test := range tests {
|
||||
if got := runeSliceWidth(test.rs); got != test.exp {
|
||||
t.Errorf("at input '%v' expected '%d' but got '%d'", test.rs, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuneSliceWidthRange(t *testing.T) {
|
||||
slices := []struct {
|
||||
s []rune
|
||||
i int
|
||||
j int
|
||||
r []rune
|
||||
tests := []struct {
|
||||
rs []rune
|
||||
beg int
|
||||
end int
|
||||
exp []rune
|
||||
}{
|
||||
{[]rune{'a', 'b', 'c', 'd'}, 1, 3, []rune{'b', 'c'}},
|
||||
{[]rune{'a', 'ı', 'b', 'ş'}, 1, 3, []rune{'ı', 'b'}},
|
||||
@@ -84,17 +84,17 @@ func TestRuneSliceWidthRange(t *testing.T) {
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, 4, []rune{}},
|
||||
}
|
||||
|
||||
for _, slice := range slices {
|
||||
if r := runeSliceWidthRange(slice.s, slice.i, slice.j); !reflect.DeepEqual(r, slice.r) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", slice.s, slice.r, r)
|
||||
for _, test := range tests {
|
||||
if got := runeSliceWidthRange(test.rs, test.beg, test.end); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.rs, test.rs, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscape(t *testing.T) {
|
||||
strs := []struct {
|
||||
s string
|
||||
e string
|
||||
tests := []struct {
|
||||
s string
|
||||
exp string
|
||||
}{
|
||||
{"", ""},
|
||||
{"foo", "foo"},
|
||||
@@ -104,17 +104,17 @@ func TestEscape(t *testing.T) {
|
||||
{`foo\bar`, `foo\bar`},
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
if e := escape(str.s); !reflect.DeepEqual(e, str.e) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", str.s, str.e, e)
|
||||
for _, test := range tests {
|
||||
if got := escape(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) {
|
||||
strs := []struct {
|
||||
s string
|
||||
u string
|
||||
tests := []struct {
|
||||
s string
|
||||
exp string
|
||||
}{
|
||||
{"", ""},
|
||||
{"foo", "foo"},
|
||||
@@ -123,17 +123,17 @@ func TestUnescape(t *testing.T) {
|
||||
{`foo\ \ bar`, "foo bar"},
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
if u := unescape(str.s); !reflect.DeepEqual(u, str.u) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", str.s, str.u, u)
|
||||
for _, test := range tests {
|
||||
if got := unescape(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokenize(t *testing.T) {
|
||||
strs := []struct {
|
||||
s string
|
||||
toks []string
|
||||
tests := []struct {
|
||||
s string
|
||||
exp []string
|
||||
}{
|
||||
{"", []string{""}},
|
||||
{"foo", []string{"foo"}},
|
||||
@@ -141,15 +141,15 @@ func TestTokenize(t *testing.T) {
|
||||
{`:rename foo\ bar`, []string{":rename", `foo\ bar`}},
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
if toks := tokenize(str.s); !reflect.DeepEqual(toks, str.toks) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", str.s, str.toks, toks)
|
||||
for _, test := range tests {
|
||||
if got := tokenize(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitWord(t *testing.T) {
|
||||
strs := []struct {
|
||||
tests := []struct {
|
||||
s string
|
||||
word string
|
||||
rest string
|
||||
@@ -165,17 +165,17 @@ func TestSplitWord(t *testing.T) {
|
||||
{" foo bar baz", "foo", "bar baz"},
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
if w, r := splitWord(str.s); w != str.word || r != str.rest {
|
||||
t.Errorf("at input '%s' expected '%s' and '%s' but got '%s' and '%s'", str.s, str.word, str.rest, w, r)
|
||||
for _, test := range tests {
|
||||
if w, r := splitWord(test.s); w != test.word || r != test.rest {
|
||||
t.Errorf("at input '%s' expected '%s' and '%s' but got '%s' and '%s'", test.s, test.word, test.rest, w, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHumanize(t *testing.T) {
|
||||
nums := []struct {
|
||||
i int64
|
||||
s string
|
||||
tests := []struct {
|
||||
i int64
|
||||
exp string
|
||||
}{
|
||||
{0, "0"},
|
||||
{9, "9"},
|
||||
@@ -194,18 +194,18 @@ func TestHumanize(t *testing.T) {
|
||||
{1000000, "1.0M"},
|
||||
}
|
||||
|
||||
for _, num := range nums {
|
||||
if h := humanize(num.i); h != num.s {
|
||||
t.Errorf("at input '%d' expected '%s' but got '%s'", num.i, num.s, h)
|
||||
for _, test := range tests {
|
||||
if got := humanize(test.i); got != test.exp {
|
||||
t.Errorf("at input '%d' expected '%s' but got '%s'", test.i, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNaturalLess(t *testing.T) {
|
||||
tests := []struct {
|
||||
s1 string
|
||||
s2 string
|
||||
expected bool
|
||||
s1 string
|
||||
s2 string
|
||||
exp bool
|
||||
}{
|
||||
{"foo", "bar", false},
|
||||
{"bar", "baz", true},
|
||||
@@ -222,8 +222,8 @@ func TestNaturalLess(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if b := naturalLess(test.s1, test.s2); b != test.expected {
|
||||
t.Errorf("at input '%s' and '%s' expected '%t' but got '%t'", test.s1, test.s2, test.expected, b)
|
||||
if got := naturalLess(test.s1, test.s2); got != test.exp {
|
||||
t.Errorf("at input '%s' and '%s' expected '%t' but got '%t'", test.s1, test.s2, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type linkState int8
|
||||
type linkState byte
|
||||
|
||||
const (
|
||||
notLink linkState = iota
|
||||
@@ -298,16 +298,12 @@ func (nav *nav) updir() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var errNotDir = fmt.Errorf("not a directory")
|
||||
|
||||
func (nav *nav) open() error {
|
||||
curr, err := nav.currFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !curr.IsDir() {
|
||||
return errNotDir
|
||||
return fmt.Errorf("open: %s", err)
|
||||
}
|
||||
|
||||
path := curr.Path
|
||||
|
||||
dir := newDir(path)
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
for _, test := range gTests {
|
||||
for _, test := range gEvalTests {
|
||||
p := newParser(strings.NewReader(test.inp))
|
||||
|
||||
for _, expr := range test.exprs {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type tokenType int
|
||||
type tokenType byte
|
||||
|
||||
const (
|
||||
tokenEOF tokenType = iota
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
for _, test := range gTests {
|
||||
for _, test := range gEvalTests {
|
||||
s := newScanner(strings.NewReader(test.inp))
|
||||
|
||||
for _, tok := range test.toks {
|
||||
|
||||
@@ -21,6 +21,28 @@ import (
|
||||
|
||||
const gEscapeCode = 27
|
||||
|
||||
var gAnsiCodes = map[int]termbox.Attribute{
|
||||
1: termbox.AttrBold,
|
||||
4: termbox.AttrUnderline,
|
||||
7: termbox.AttrReverse,
|
||||
30: termbox.ColorBlack,
|
||||
31: termbox.ColorRed,
|
||||
32: termbox.ColorGreen,
|
||||
33: termbox.ColorYellow,
|
||||
34: termbox.ColorBlue,
|
||||
35: termbox.ColorMagenta,
|
||||
36: termbox.ColorCyan,
|
||||
37: termbox.ColorWhite,
|
||||
40: termbox.ColorBlack,
|
||||
41: termbox.ColorRed,
|
||||
42: termbox.ColorGreen,
|
||||
43: termbox.ColorYellow,
|
||||
44: termbox.ColorBlue,
|
||||
45: termbox.ColorMagenta,
|
||||
46: termbox.ColorCyan,
|
||||
47: termbox.ColorWhite,
|
||||
}
|
||||
|
||||
var gKeyVal = map[termbox.Key][]rune{
|
||||
termbox.KeyF1: []rune{'<', 'f', '-', '1', '>'},
|
||||
termbox.KeyF2: []rune{'<', 'f', '-', '2', '>'},
|
||||
@@ -114,7 +136,6 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) {
|
||||
|
||||
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
|
||||
j := strings.IndexByte(s[i:min(len(s), i+32)], 'm')
|
||||
|
||||
if j == -1 {
|
||||
continue
|
||||
}
|
||||
@@ -146,45 +167,16 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) {
|
||||
}
|
||||
|
||||
for _, n := range nums {
|
||||
switch n {
|
||||
case 1:
|
||||
fg = fg | termbox.AttrBold
|
||||
case 4:
|
||||
fg = fg | termbox.AttrUnderline
|
||||
case 7:
|
||||
fg = fg | termbox.AttrReverse
|
||||
case 30:
|
||||
fg = fg | termbox.ColorBlack
|
||||
case 31:
|
||||
fg = fg | termbox.ColorRed
|
||||
case 32:
|
||||
fg = fg | termbox.ColorGreen
|
||||
case 33:
|
||||
fg = fg | termbox.ColorYellow
|
||||
case 34:
|
||||
fg = fg | termbox.ColorBlue
|
||||
case 35:
|
||||
fg = fg | termbox.ColorMagenta
|
||||
case 36:
|
||||
fg = fg | termbox.ColorCyan
|
||||
case 37:
|
||||
fg = fg | termbox.ColorWhite
|
||||
case 40:
|
||||
bg = bg | termbox.ColorBlack
|
||||
case 41:
|
||||
bg = bg | termbox.ColorRed
|
||||
case 42:
|
||||
bg = bg | termbox.ColorGreen
|
||||
case 43:
|
||||
bg = bg | termbox.ColorYellow
|
||||
case 44:
|
||||
bg = bg | termbox.ColorBlue
|
||||
case 45:
|
||||
bg = bg | termbox.ColorMagenta
|
||||
case 46:
|
||||
bg = bg | termbox.ColorCyan
|
||||
case 47:
|
||||
bg = bg | termbox.ColorWhite
|
||||
attr, ok := gAnsiCodes[n]
|
||||
if !ok {
|
||||
log.Printf("unknown ansi code: %d", n)
|
||||
continue
|
||||
}
|
||||
if 1 <= n && n <= 37 {
|
||||
fg = fg | attr
|
||||
}
|
||||
if 40 <= n && n <= 47 {
|
||||
bg = bg | attr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +217,7 @@ func (win *win) printd(dir *dir, marks, saves map[string]bool) {
|
||||
|
||||
if len(dir.fi) == 0 {
|
||||
fg = termbox.AttrBold
|
||||
win.print(0, 0, fg, bg, "empty")
|
||||
win.print(2, 0, fg, bg, "empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -236,15 +228,13 @@ func (win *win) printd(dir *dir, marks, saves map[string]bool) {
|
||||
|
||||
for i, f := range dir.fi[beg:end] {
|
||||
switch {
|
||||
case f.LinkState != notLink:
|
||||
if f.LinkState == working {
|
||||
fg = termbox.ColorCyan
|
||||
if f.Mode().IsDir() {
|
||||
fg |= termbox.AttrBold
|
||||
}
|
||||
} else {
|
||||
fg = termbox.ColorMagenta
|
||||
case f.LinkState == working:
|
||||
fg = termbox.ColorCyan
|
||||
if f.Mode().IsDir() {
|
||||
fg |= termbox.AttrBold
|
||||
}
|
||||
case f.LinkState == broken:
|
||||
fg = termbox.ColorMagenta
|
||||
case f.Mode().IsRegular():
|
||||
if f.Mode()&0111 != 0 {
|
||||
fg = termbox.AttrBold | termbox.ColorGreen
|
||||
@@ -343,11 +333,13 @@ type ui struct {
|
||||
dirprev *dir
|
||||
keychan chan string
|
||||
evschan chan termbox.Event
|
||||
menubuf *bytes.Buffer
|
||||
cmdpref string
|
||||
cmdlacc []rune
|
||||
cmdracc []rune
|
||||
cmdbuf []rune
|
||||
menubuf *bytes.Buffer
|
||||
keyacc []rune
|
||||
keycnt []rune
|
||||
}
|
||||
|
||||
func getWidths(wtot int) []int {
|
||||
@@ -481,7 +473,7 @@ func (ui *ui) loadFile(nav *nav) {
|
||||
for i := 0; i < nav.height && buf.Scan(); i++ {
|
||||
for _, r := range buf.Text() {
|
||||
if r == 0 {
|
||||
ui.regprev = []string{"[1mbinary[0m"}
|
||||
ui.regprev = []string{"\033[1mbinary\033[0m"}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -556,8 +548,8 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
ui.menuwin.printl(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0])
|
||||
for i, line := range lines[1:] {
|
||||
ui.menuwin.printl(0, i+1, termbox.ColorDefault, termbox.ColorDefault, "")
|
||||
ui.menuwin.print(0, i+1, termbox.ColorDefault, termbox.ColorDefault, line)
|
||||
ui.menuwin.printl(0, i+1, fg, bg, "")
|
||||
ui.menuwin.print(0, i+1, fg, bg, line)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,7 +557,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
if ui.cmdpref == "" {
|
||||
// leave the cursor at the beginning of the current file for screen readers
|
||||
fmt.Printf("[%d;%dH", ui.wins[woff+length-1].y+nav.dirs[doff+length-1].pos+1, ui.wins[woff+length-1].x+1)
|
||||
fmt.Printf("\033[%d;%dH", ui.wins[woff+length-1].y+nav.dirs[doff+length-1].pos+1, ui.wins[woff+length-1].x+1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,148 +630,150 @@ type multiExpr struct {
|
||||
count int
|
||||
}
|
||||
|
||||
// This function is used to read expressions on the client side. Digits are
|
||||
// interpreted as command counts but this is only done for digits preceding any
|
||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||
func (ui *ui) readExpr() chan multiExpr {
|
||||
ch := make(chan multiExpr)
|
||||
func readCmdEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{string(ev.Ch)}}, 1}
|
||||
} else {
|
||||
// TODO: rest of the keys
|
||||
switch ev.Key {
|
||||
case termbox.KeyEsc:
|
||||
ch <- multiExpr{&callExpr{"cmd-escape", nil}, 1}
|
||||
case termbox.KeySpace:
|
||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{" "}}, 1}
|
||||
case termbox.KeyTab:
|
||||
ch <- multiExpr{&callExpr{"cmd-comp", nil}, 1}
|
||||
case termbox.KeyEnter, termbox.KeyCtrlJ:
|
||||
ch <- multiExpr{&callExpr{"cmd-enter", nil}, 1}
|
||||
case termbox.KeyBackspace, termbox.KeyBackspace2:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-back", nil}, 1}
|
||||
case termbox.KeyDelete, termbox.KeyCtrlD:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete", nil}, 1}
|
||||
case termbox.KeyArrowLeft, termbox.KeyCtrlB:
|
||||
ch <- multiExpr{&callExpr{"cmd-left", nil}, 1}
|
||||
case termbox.KeyArrowRight, termbox.KeyCtrlF:
|
||||
ch <- multiExpr{&callExpr{"cmd-right", nil}, 1}
|
||||
case termbox.KeyHome, termbox.KeyCtrlA:
|
||||
ch <- multiExpr{&callExpr{"cmd-beg", nil}, 1}
|
||||
case termbox.KeyEnd, termbox.KeyCtrlE:
|
||||
ch <- multiExpr{&callExpr{"cmd-end", nil}, 1}
|
||||
case termbox.KeyCtrlK:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-end", nil}, 1}
|
||||
case termbox.KeyCtrlU:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-beg", nil}, 1}
|
||||
case termbox.KeyCtrlW:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-word", nil}, 1}
|
||||
case termbox.KeyCtrlY:
|
||||
ch <- multiExpr{&callExpr{"cmd-put", nil}, 1}
|
||||
case termbox.KeyCtrlT:
|
||||
ch <- multiExpr{&callExpr{"cmd-transpose", nil}, 1}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
renew := &callExpr{"renew", nil}
|
||||
count := 1
|
||||
|
||||
var acc []rune
|
||||
var cnt []rune
|
||||
switch ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Ch != 0 {
|
||||
switch {
|
||||
case ev.Ch == '<':
|
||||
ui.keyacc = append(ui.keyacc, '<', 'l', 't', '>')
|
||||
case ev.Ch == '>':
|
||||
ui.keyacc = append(ui.keyacc, '<', 'g', 't', '>')
|
||||
case unicode.IsDigit(ev.Ch) && len(ui.keyacc) == 0:
|
||||
ui.keycnt = append(ui.keycnt, ev.Ch)
|
||||
default:
|
||||
ui.keyacc = append(ui.keyacc, ev.Ch)
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if string(val) == "<esc>" {
|
||||
ch <- multiExpr{renew, 1}
|
||||
ui.keyacc = nil
|
||||
ui.keycnt = nil
|
||||
}
|
||||
ui.keyacc = append(ui.keyacc, val...)
|
||||
}
|
||||
|
||||
binds, ok := findBinds(gOpts.keys, string(ui.keyacc))
|
||||
|
||||
switch len(binds) {
|
||||
case 0:
|
||||
ui.message = fmt.Sprintf("unknown mapping: %s", string(ui.keyacc))
|
||||
ch <- multiExpr{renew, 1}
|
||||
ui.keyacc = nil
|
||||
ui.keycnt = nil
|
||||
case 1:
|
||||
if ok {
|
||||
if len(ui.keycnt) > 0 {
|
||||
c, err := strconv.Atoi(string(ui.keycnt))
|
||||
if err != nil {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyacc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
ui.keyacc = nil
|
||||
ui.keycnt = nil
|
||||
}
|
||||
if len(ui.keyacc) > 0 {
|
||||
ui.menubuf = listBinds(binds)
|
||||
ch <- multiExpr{renew, 1}
|
||||
} else if ui.menubuf != nil {
|
||||
ui.menubuf = nil
|
||||
}
|
||||
default:
|
||||
if ok {
|
||||
// TODO: use a delay
|
||||
if len(ui.keycnt) > 0 {
|
||||
c, err := strconv.Atoi(string(ui.keycnt))
|
||||
if err != nil {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyacc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
ui.keyacc = nil
|
||||
ui.keycnt = nil
|
||||
}
|
||||
if len(ui.keyacc) > 0 {
|
||||
ui.menubuf = listBinds(binds)
|
||||
ch <- multiExpr{renew, 1}
|
||||
} else {
|
||||
ui.menubuf = nil
|
||||
}
|
||||
}
|
||||
case termbox.EventResize:
|
||||
ch <- multiExpr{renew, 1}
|
||||
default:
|
||||
// TODO: handle other events
|
||||
}
|
||||
}
|
||||
|
||||
// This function is used to read expressions on the client side. Digits are
|
||||
// interpreted as command counts but this is only done for digits preceding any
|
||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||
func (ui *ui) readExpr() <-chan multiExpr {
|
||||
ch := make(chan multiExpr)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
ev := ui.pollEvent()
|
||||
|
||||
if ui.cmdpref != "" {
|
||||
switch ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Ch != 0 {
|
||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{string(ev.Ch)}}, 1}
|
||||
} else {
|
||||
// TODO: rest of the keys
|
||||
switch ev.Key {
|
||||
case termbox.KeyEsc:
|
||||
ch <- multiExpr{&callExpr{"cmd-escape", nil}, 1}
|
||||
case termbox.KeySpace:
|
||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{" "}}, 1}
|
||||
case termbox.KeyTab:
|
||||
ch <- multiExpr{&callExpr{"cmd-comp", nil}, 1}
|
||||
case termbox.KeyEnter, termbox.KeyCtrlJ:
|
||||
ch <- multiExpr{&callExpr{"cmd-enter", nil}, 1}
|
||||
case termbox.KeyBackspace, termbox.KeyBackspace2:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-back", nil}, 1}
|
||||
case termbox.KeyDelete, termbox.KeyCtrlD:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete", nil}, 1}
|
||||
case termbox.KeyArrowLeft, termbox.KeyCtrlB:
|
||||
ch <- multiExpr{&callExpr{"cmd-left", nil}, 1}
|
||||
case termbox.KeyArrowRight, termbox.KeyCtrlF:
|
||||
ch <- multiExpr{&callExpr{"cmd-right", nil}, 1}
|
||||
case termbox.KeyHome, termbox.KeyCtrlA:
|
||||
ch <- multiExpr{&callExpr{"cmd-beg", nil}, 1}
|
||||
case termbox.KeyEnd, termbox.KeyCtrlE:
|
||||
ch <- multiExpr{&callExpr{"cmd-end", nil}, 1}
|
||||
case termbox.KeyCtrlK:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-end", nil}, 1}
|
||||
case termbox.KeyCtrlU:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-beg", nil}, 1}
|
||||
case termbox.KeyCtrlW:
|
||||
ch <- multiExpr{&callExpr{"cmd-delete-word", nil}, 1}
|
||||
case termbox.KeyCtrlY:
|
||||
ch <- multiExpr{&callExpr{"cmd-put", nil}, 1}
|
||||
case termbox.KeyCtrlT:
|
||||
ch <- multiExpr{&callExpr{"cmd-transpose", nil}, 1}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ui.cmdpref != "" && ev.Type == termbox.EventKey {
|
||||
readCmdEvent(ch, ev)
|
||||
continue
|
||||
}
|
||||
|
||||
switch ev.Type {
|
||||
case termbox.EventKey:
|
||||
if ev.Ch != 0 {
|
||||
switch {
|
||||
case ev.Ch == '<':
|
||||
acc = append(acc, '<', 'l', 't', '>')
|
||||
case ev.Ch == '>':
|
||||
acc = append(acc, '<', 'g', 't', '>')
|
||||
case unicode.IsDigit(ev.Ch) && len(acc) == 0:
|
||||
cnt = append(cnt, ev.Ch)
|
||||
default:
|
||||
acc = append(acc, ev.Ch)
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if string(val) == "<esc>" {
|
||||
ch <- multiExpr{renew, 1}
|
||||
acc = nil
|
||||
cnt = nil
|
||||
}
|
||||
acc = append(acc, val...)
|
||||
}
|
||||
|
||||
binds, ok := findBinds(gOpts.keys, string(acc))
|
||||
|
||||
switch len(binds) {
|
||||
case 0:
|
||||
ui.message = fmt.Sprintf("unknown mapping: %s", string(acc))
|
||||
ch <- multiExpr{renew, 1}
|
||||
acc = nil
|
||||
cnt = nil
|
||||
case 1:
|
||||
if ok {
|
||||
if len(cnt) > 0 {
|
||||
c, err := strconv.Atoi(string(cnt))
|
||||
if err != nil {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(acc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
acc = nil
|
||||
cnt = nil
|
||||
}
|
||||
if len(acc) > 0 {
|
||||
ui.menubuf = listBinds(binds)
|
||||
ch <- multiExpr{renew, 1}
|
||||
} else if ui.menubuf != nil {
|
||||
ui.menubuf = nil
|
||||
}
|
||||
default:
|
||||
if ok {
|
||||
// TODO: use a delay
|
||||
if len(cnt) > 0 {
|
||||
c, err := strconv.Atoi(string(cnt))
|
||||
if err != nil {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(acc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
acc = nil
|
||||
cnt = nil
|
||||
}
|
||||
if len(acc) > 0 {
|
||||
ui.menubuf = listBinds(binds)
|
||||
ch <- multiExpr{renew, 1}
|
||||
} else {
|
||||
ui.menubuf = nil
|
||||
}
|
||||
}
|
||||
case termbox.EventResize:
|
||||
ch <- multiExpr{renew, 1}
|
||||
default:
|
||||
// TODO: handle other events
|
||||
}
|
||||
ui.readEvent(ch, ev)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in new issue
Block a user