diff options
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/README.md | 6 | ||||
-rw-r--r-- | src/ansi.go | 28 | ||||
-rw-r--r-- | src/ansi_test.go | 8 | ||||
-rw-r--r-- | src/constants.go | 1 | ||||
-rw-r--r-- | src/constants_unix.go | 8 | ||||
-rw-r--r-- | src/constants_windows.go | 8 | ||||
-rw-r--r-- | src/options.go | 88 | ||||
-rw-r--r-- | src/options_test.go | 172 | ||||
-rw-r--r-- | src/result.go | 20 | ||||
-rw-r--r-- | src/result_test.go | 24 | ||||
-rw-r--r-- | src/terminal.go | 189 | ||||
-rw-r--r-- | src/terminal_unix.go | 13 | ||||
-rw-r--r-- | src/terminal_windows.go | 11 | ||||
-rw-r--r-- | src/tui/ncurses.go (renamed from src/curses/curses.go) | 543 | ||||
-rw-r--r-- | src/tui/termbox.go | 151 | ||||
-rw-r--r-- | src/tui/tui.go | 250 | ||||
-rw-r--r-- | src/tui/tui_test.go (renamed from src/curses/curses_test.go) | 2 | ||||
-rw-r--r-- | src/util/util.go | 17 | ||||
-rw-r--r-- | src/util/util_unix.go | 17 | ||||
-rw-r--r-- | src/util/util_windows.go | 17 |
21 files changed, 920 insertions, 655 deletions
diff --git a/src/Makefile b/src/Makefile index f7aa0b2d..edc77faf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,7 +43,7 @@ $(SRCDIR): ln -s $(ROOTDIR) $(SRCDIR) deps: $(SRCDIR) $(SOURCES) - cd $(SRCDIR) && go get + cd $(SRCDIR) && go get -tags "$(TAGS)" android-build: $(SRCDIR) cd $(SRCDIR) && GOARCH=arm GOARM=7 CGO_ENABLED=1 go get diff --git a/src/README.md b/src/README.md index 272c7554..e8b8debc 100644 --- a/src/README.md +++ b/src/README.md @@ -83,9 +83,11 @@ Third-party libraries used - [ncurses][ncurses] - [mattn/go-runewidth](https://github.com/mattn/go-runewidth) - - Licensed under [MIT](http://mattn.mit-license.org/2013) + - Licensed under [MIT](http://mattn.mit-license.org) - [mattn/go-shellwords](https://github.com/mattn/go-shellwords) - - Licensed under [MIT](http://mattn.mit-license.org/2014) + - Licensed under [MIT](http://mattn.mit-license.org) +- [mattn/go-isatty](https://github.com/mattn/go-isatty) + - Licensed under [MIT](http://mattn.mit-license.org) License ------- diff --git a/src/ansi.go b/src/ansi.go index 02be18c6..b7d3a9e3 100644 --- a/src/ansi.go +++ b/src/ansi.go @@ -7,7 +7,7 @@ import ( "strings" "unicode/utf8" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" ) type ansiOffset struct { @@ -16,9 +16,9 @@ type ansiOffset struct { } type ansiState struct { - fg int - bg int - attr curses.Attr + fg tui.Color + bg tui.Color + attr tui.Attr } func (s *ansiState) colored() bool { @@ -134,26 +134,26 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState { case 49: state.bg = -1 case 1: - state.attr = curses.Bold + state.attr = tui.Bold case 2: - state.attr = curses.Dim + state.attr = tui.Dim case 4: - state.attr = curses.Underline + state.attr = tui.Underline case 5: - state.attr = curses.Blink + state.attr = tui.Blink case 7: - state.attr = curses.Reverse + state.attr = tui.Reverse case 0: init() default: if num >= 30 && num <= 37 { - state.fg = num - 30 + state.fg = tui.Color(num - 30) } else if num >= 40 && num <= 47 { - state.bg = num - 40 + state.bg = tui.Color(num - 40) } else if num >= 90 && num <= 97 { - state.fg = num - 90 + 8 + state.fg = tui.Color(num - 90 + 8) } else if num >= 100 && num <= 107 { - state.bg = num - 100 + 8 + state.bg = tui.Color(num - 100 + 8) } } case 1: @@ -164,7 +164,7 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState { state256 = 0 } case 2: - *ptr = num + *ptr = tui.Color(num) state256 = 0 } } diff --git a/src/ansi_test.go b/src/ansi_test.go index 0ba9e400..3afcc6c5 100644 --- a/src/ansi_test.go +++ b/src/ansi_test.go @@ -4,14 +4,14 @@ import ( "fmt" "testing" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" ) func TestExtractColor(t *testing.T) { - assert := func(offset ansiOffset, b int32, e int32, fg int, bg int, bold bool) { - var attr curses.Attr + assert := func(offset ansiOffset, b int32, e int32, fg tui.Color, bg tui.Color, bold bool) { + var attr tui.Attr if bold { - attr = curses.Bold + attr = tui.Bold } if offset.offset[0] != b || offset.offset[1] != e || offset.color.fg != fg || offset.color.bg != bg || offset.color.attr != attr { diff --git a/src/constants.go b/src/constants.go index bec3bb6c..778d219a 100644 --- a/src/constants.go +++ b/src/constants.go @@ -15,7 +15,6 @@ const ( coordinatorDelayStep time.Duration = 10 * time.Millisecond // Reader - defaultCommand = `find . -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | sed s/^..//` readerBufferSize = 64 * 1024 // Terminal diff --git a/src/constants_unix.go b/src/constants_unix.go new file mode 100644 index 00000000..52677e6c --- /dev/null +++ b/src/constants_unix.go @@ -0,0 +1,8 @@ +// +build !windows + +package fzf + +const ( + // Reader + defaultCommand = `find . -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | sed s/^..//` +) diff --git a/src/constants_windows.go b/src/constants_windows.go new file mode 100644 index 00000000..efd3f11c --- /dev/null +++ b/src/constants_windows.go @@ -0,0 +1,8 @@ +// +build windows + +package fzf + +const ( + // Reader + defaultCommand = `dir /s/b` +) diff --git a/src/options.go b/src/options.go index c5e6d7b7..a3ed22d9 100644 --- a/src/options.go +++ b/src/options.go @@ -9,7 +9,7 @@ import ( "unicode/utf8" "github.com/junegunn/fzf/src/algo" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" "github.com/junegunn/go-shellwords" ) @@ -142,7 +142,7 @@ type Options struct { Multi bool Ansi bool Mouse bool - Theme *curses.ColorTheme + Theme *tui.ColorTheme Black bool Reverse bool Cycle bool @@ -187,7 +187,7 @@ func defaultOptions() *Options { Multi: false, Ansi: false, Mouse: true, - Theme: curses.EmptyTheme(), + Theme: tui.EmptyTheme(), Black: false, Reverse: false, Cycle: false, @@ -358,60 +358,60 @@ func parseKeyChords(str string, message string) map[int]string { chord := 0 switch lkey { case "up": - chord = curses.Up + chord = tui.Up case "down": - chord = curses.Down + chord = tui.Down case "left": - chord = curses.Left + chord = tui.Left case "right": - chord = curses.Right + chord = tui.Right case "enter", "return": - chord = curses.CtrlM + chord = tui.CtrlM case "space": - chord = curses.AltZ + int(' ') + chord = tui.AltZ + int(' ') case "bspace", "bs": - chord = curses.BSpace + chord = tui.BSpace case "alt-enter", "alt-return": - chord = curses.AltEnter + chord = tui.AltEnter case "alt-space": - chord = curses.AltSpace + chord = tui.AltSpace case "alt-/": - chord = curses.AltSlash + chord = tui.AltSlash case "alt-bs", "alt-bspace": - chord = curses.AltBS + chord = tui.AltBS case "tab": - chord = curses.Tab + chord = tui.Tab case "btab", "shift-tab": - chord = curses.BTab + chord = tui.BTab case "esc": - chord = curses.ESC + chord = tui.ESC case "del": - chord = curses.Del + chord = tui.Del case "home": - chord = curses.Home + chord = tui.Home case "end": - chord = curses.End + chord = tui.End case "pgup", "page-up": - chord = curses.PgUp + chord = tui.PgUp case "pgdn", "page-down": - chord = curses.PgDn + chord = tui.PgDn case "shift-left": - chord = curses.SLeft + chord = tui.SLeft case "shift-right": - chord = curses.SRight + chord = tui.SRight case "double-click": - chord = curses.DoubleClick + chord = tui.DoubleClick case "f10": - chord = curses.F10 + chord = tui.F10 default: if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) { - chord = curses.CtrlA + int(lkey[5]) - 'a' + chord = tui.CtrlA + int(lkey[5]) - 'a' } else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) { - chord = curses.AltA + int(lkey[4]) - 'a' + chord = tui.AltA + int(lkey[4]) - 'a' } else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '9' { - chord = curses.F1 + int(key[1]) - '1' + chord = tui.F1 + int(key[1]) - '1' } else if utf8.RuneCountInString(key) == 1 { - chord = curses.AltZ + int([]rune(key)[0]) + chord = tui.AltZ + int([]rune(key)[0]) } else { errorExit("unsupported key: " + key) } @@ -458,7 +458,7 @@ func parseTiebreak(str string) []criterion { return criteria } -func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme { +func dupeTheme(theme *tui.ColorTheme) *tui.ColorTheme { if theme != nil { dupe := *theme return &dupe @@ -466,16 +466,16 @@ func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme { return nil } -func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme { +func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme { theme := dupeTheme(defaultTheme) for _, str := range strings.Split(strings.ToLower(str), ",") { switch str { case "dark": - theme = dupeTheme(curses.Dark256) + theme = dupeTheme(tui.Dark256) case "light": - theme = dupeTheme(curses.Light256) + theme = dupeTheme(tui.Light256) case "16": - theme = dupeTheme(curses.Default16) + theme = dupeTheme(tui.Default16) case "bw", "no": theme = nil default: @@ -495,7 +495,7 @@ func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme if err != nil || ansi32 < -1 || ansi32 > 255 { fail() } - ansi := int16(ansi32) + ansi := tui.Color(ansi32) switch pair[0] { case "fg": theme.Fg = ansi @@ -572,9 +572,9 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, str string) } var key int if len(pair[0]) == 1 && pair[0][0] == escapedColon { - key = ':' + curses.AltZ + key = ':' + tui.AltZ } else if len(pair[0]) == 1 && pair[0][0] == escapedComma { - key = ',' + curses.AltZ + key = ',' + tui.AltZ } else { keys := parseKeyChords(pair[0], "key name required") key = firstKey(keys) @@ -868,7 +868,7 @@ func parseOptions(opts *Options, allArgs []string) { case "--color": spec := optionalNextString(allArgs, &i) if len(spec) == 0 { - opts.Theme = curses.EmptyTheme() + opts.Theme = tui.EmptyTheme() } else { opts.Theme = parseTheme(opts.Theme, spec) } @@ -905,7 +905,7 @@ func parseOptions(opts *Options, allArgs []string) { case "+c", "--no-color": opts.Theme = nil case "+2", "--no-256": - opts.Theme = curses.Default16 + opts.Theme = tui.Default16 case "--black": opts.Black = true case "--no-black": @@ -1071,11 +1071,11 @@ func parseOptions(opts *Options, allArgs []string) { func postProcessOptions(opts *Options) { // Default actions for CTRL-N / CTRL-P when --history is set if opts.History != nil { - if _, prs := opts.Keymap[curses.CtrlP]; !prs { - opts.Keymap[curses.CtrlP] = actPreviousHistory + if _, prs := opts.Keymap[tui.CtrlP]; !prs { + opts.Keymap[tui.CtrlP] = actPreviousHistory } - if _, prs := opts.Keymap[curses.CtrlN]; !prs { - opts.Keymap[curses.CtrlN] = actNextHistory + if _, prs := opts.Keymap[tui.CtrlN]; !prs { + opts.Keymap[tui.CtrlN] = actNextHistory } } diff --git a/src/options_test.go b/src/options_test.go index 60136173..f16569e3 100644 --- a/src/options_test.go +++ b/src/options_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" "github.com/junegunn/fzf/src/util" ) @@ -133,48 +133,48 @@ func TestParseKeys(t *testing.T) { if len(pairs) != 11 { t.Error(11) } - check(curses.CtrlZ, "ctrl-z") - check(curses.AltZ, "alt-z") - check(curses.F2, "f2") - check(curses.AltZ+'@', "@") - check(curses.AltA, "Alt-a") - check(curses.AltZ+'!', "!") - check(curses.CtrlA+'g'-'a', "ctrl-G") - check(curses.AltZ+'J', "J") - check(curses.AltZ+'g', "g") - check(curses.AltEnter, "ALT-enter") - check(curses.AltSpace, "alt-SPACE") + check(tui.CtrlZ, "ctrl-z") + check(tui.AltZ, "alt-z") + check(tui.F2, "f2") + check(tui.AltZ+'@', "@") + check(tui.AltA, "Alt-a") + check(tui.AltZ+'!', "!") + check(tui.CtrlA+'g'-'a', "ctrl-G") + check(tui.AltZ+'J', "J") + check(tui.AltZ+'g', "g") + check(tui.AltEnter, "ALT-enter") + check(tui.AltSpace, "alt-SPACE") // Synonyms pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "") if len(pairs) != 9 { t.Error(9) } - check(curses.CtrlM, "Return") - check(curses.AltZ+' ', "space") - check(curses.Tab, "tab") - check(curses.BTab, "btab") - check(curses.ESC, "esc") - check(curses.Up, "up") - check(curses.Down, "down") - check(curses.Left, "left") - check(curses.Right, "right") + check(tui.CtrlM, "Return") + check(tui.AltZ+' ', "space") + check(tui.Tab, "tab") + check(tui.BTab, "btab") + check(tui.ESC, "esc") + check(tui.Up, "up") + check(tui.Down, "down") + check(tui.Left, "left") + check(tui.Right, "right") pairs = parseKeyChords("Tab,Ctrl-I,PgUp,page-up,pgdn,Page-Down,Home,End,Alt-BS,Alt-BSpace,shift-left,shift-right,btab,shift-tab,return,Enter,bspace", "") if len(pairs) != 11 { t.Error(11) } - check(curses.Tab, "Ctrl-I") - check(curses.PgUp, "page-up") - check(curses.PgDn, "Page-Down") - check(curses.Home, "Home") - check(curses.End, "End") - check(curses.AltBS, "Alt-BSpace") - check(curses.SLeft, "shift-left") - check(curses.SRight, "shift-right") - check(curses.BTab, "shift-tab") - check(curses.CtrlM, "Enter") - check(curses.BSpace, "bspace") + check(tui.Tab, "Ctrl-I") + check(tui.PgUp, "page-up") + check(tui.PgDn, "Page-Down") + check(tui.Home, "Home") + check(tui.End, "End") + check(tui.AltBS, "Alt-BSpace") + check(tui.SLeft, "shift-left") + check(tui.SRight, "shift-right") + check(tui.BTab, "shift-tab") + check(tui.CtrlM, "Enter") + check(tui.BSpace, "bspace") } func TestParseKeysWithComma(t *testing.T) { @@ -191,36 +191,36 @@ func TestParseKeysWithComma(t *testing.T) { pairs := parseKeyChords(",", "") checkN(len(pairs), 1) - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+',', ",") pairs = parseKeyChords(",,a,b", "") checkN(len(pairs), 3) - check(pairs, curses.AltZ+'a', "a") - check(pairs, curses.AltZ+'b', "b") - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+'a', "a") + check(pairs, tui.AltZ+'b', "b") + check(pairs, tui.AltZ+',', ",") pairs = parseKeyChords("a,b,,", "") checkN(len(pairs), 3) - check(pairs, curses.AltZ+'a', "a") - check(pairs, curses.AltZ+'b', "b") - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+'a', "a") + check(pairs, tui.AltZ+'b', "b") + check(pairs, tui.AltZ+',', ",") pairs = parseKeyChords("a,,,b", "") checkN(len(pairs), 3) - check(pairs, curses.AltZ+'a', "a") - check(pairs, curses.AltZ+'b', "b") - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+'a', "a") + check(pairs, tui.AltZ+'b', "b") + check(pairs, tui.AltZ+',', ",") pairs = parseKeyChords("a,,,b,c", "") checkN(len(pairs), 4) - check(pairs, curses.AltZ+'a', "a") - check(pairs, curses.AltZ+'b', "b") - check(pairs, curses.AltZ+'c', "c") - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+'a', "a") + check(pairs, tui.AltZ+'b', "b") + check(pairs, tui.AltZ+'c', "c") + check(pairs, tui.AltZ+',', ",") pairs = parseKeyChords(",,,", "") checkN(len(pairs), 1) - check(pairs, curses.AltZ+',', ",") + check(pairs, tui.AltZ+',', ",") } func TestBind(t *testing.T) { @@ -236,41 +236,41 @@ func TestBind(t *testing.T) { } keymap := defaultKeymap() execmap := make(map[int]string) - check(actBeginningOfLine, keymap[curses.CtrlA]) + check(actBeginningOfLine, keymap[tui.CtrlA]) parseKeymap(keymap, execmap, "ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+ "f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+ "alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+ ",,:abort,::accept,X:execute:\nfoobar,Y:execute(baz)") - check(actKillLine, keymap[curses.CtrlA]) - check(actToggleSort, keymap[curses.CtrlB]) - check(actPageUp, keymap[curses.AltZ+'c']) - check(actAbort, keymap[curses.AltZ+',']) - check(actAccept, keymap[curses.AltZ+':']) - check(actPageDown, keymap[curses.AltZ]) - check(actExecute, keymap[curses.F1]) - check(actExecute, keymap[curses.F2]) - check(actExecute, keymap[curses.F3]) - check(actExecute, keymap[curses.F4]) - checkString("ls {}", execmap[curses.F1]) - checkString("echo {}, {}, {}", execmap[curses.F2]) - checkString("echo '({})'", execmap[curses.F3]) - checkString("less {}", execmap[curses.F4]) - checkString("echo (,),[,],/,:,;,%,{}", execmap[curses.AltA]) - checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB]) - checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X']) + check(actKillLine, keymap[tui.CtrlA]) + check(actToggleSort, keymap[tui.CtrlB]) + check(actPageUp, keymap[tui.AltZ+'c']) + check(actAbort, keymap[tui.AltZ+',']) + check(actAccept, keymap[tui.AltZ+':']) + check(actPageDown, keymap[tui.AltZ]) + check(actExecute, keymap[tui.F1]) + check(actExecute, keymap[tui.F2]) + check(actExecute, keymap[tui.F3]) + check(actExecute, keymap[tui.F4]) + checkString("ls {}", execmap[tui.F1]) + checkString("echo {}, {}, {}", execmap[tui.F2]) + checkString("echo '({})'", execmap[tui.F3]) + checkString("less {}", execmap[tui.F4]) + checkString("echo (,),[,],/,:,;,%,{}", execmap[tui.AltA]) + checkString("echo (,),[,],/,:,@,%,{}", execmap[tui.AltB]) + checkString("\nfoobar,Y:execute(baz)", execmap[tui.AltZ+'X']) for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} { parseKeymap(keymap, execmap, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char)) - checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])]) + checkString("foobar", execmap[tui.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])]) } parseKeymap(keymap, execmap, "f1:abort") - check(actAbort, keymap[curses.F1]) + check(actAbort, keymap[tui.F1]) } func TestColorSpec(t *testing.T) { - theme := curses.Dark256 + theme := tui.Dark256 dark := parseTheme(theme, "dark") if *dark != *theme { t.Errorf("colors should be equivalent") @@ -283,7 +283,7 @@ func TestColorSpec(t *testing.T) { if *light == *theme { t.Errorf("should not be equivalent") } - if *light != *curses.Light256 { + if *light != *tui.Light256 { t.Errorf("colors should be equivalent") } if light == theme { @@ -294,23 +294,23 @@ func TestColorSpec(t *testing.T) { if customized.Fg != 231 || customized.Bg != 232 { t.Errorf("color not customized") } - if *curses.Dark256 == *customized { + if *tui.Dark256 == *customized { t.Errorf("colors should not be equivalent") } - customized.Fg = curses.Dark256.Fg - customized.Bg = curses.Dark256.Bg - if *curses.Dark256 != *customized { - t.Errorf("colors should now be equivalent: %v, %v", curses.Dark256, customized) + customized.Fg = tui.Dark256.Fg + customized.Bg = tui.Dark256.Bg + if *tui.Dark256 != *customized { + t.Errorf("colors should now be equivalent: %v, %v", tui.Dark256, customized) } customized = parseTheme(theme, "fg:231,dark,bg:232") - if customized.Fg != curses.Dark256.Fg || customized.Bg == curses.Dark256.Bg { + if customized.Fg != tui.Dark256.Fg || customized.Bg == tui.Dark256.Bg { t.Errorf("color not customized") } } func TestParseNilTheme(t *testing.T) { - var theme *curses.ColorTheme + var theme *tui.ColorTheme newTheme := parseTheme(theme, "prompt:12") if newTheme != nil { t.Errorf("color is disabled. keep it that way.") @@ -330,21 +330,21 @@ func TestDefaultCtrlNP(t *testing.T) { t.Error() } } - check([]string{}, curses.CtrlN, actDown) - check([]string{}, curses.CtrlP, actUp) + check([]string{}, tui.CtrlN, actDown) + check([]string{}, tui.CtrlP, actUp) - check([]string{"--bind=ctrl-n:accept"}, curses.CtrlN, actAccept) - check([]string{"--bind=ctrl-p:accept"}, curses.CtrlP, actAccept) + check([]string{"--bind=ctrl-n:accept"}, tui.CtrlN, actAccept) + check([]string{"--bind=ctrl-p:accept"}, tui.CtrlP, actAccept) hist := "--history=/tmp/fzf-history" - check([]string{hist}, curses.CtrlN, actNextHistory) - check([]string{hist}, curses.CtrlP, actPreviousHistory) + check([]string{hist}, tui.CtrlN, actNextHistory) + check([]string{hist}, tui.CtrlP, actPreviousHistory) - check([]string{hist, "--bind=ctrl-n:accept"}, curses.CtrlN, actAccept) - check([]string{hist, "--bind=ctrl-n:accept"}, curses.CtrlP, actPreviousHistory) + check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlN, actAccept) + check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlP, actPreviousHistory) - check([]string{hist, "--bind=ctrl-p:accept"}, curses.CtrlN, actNextHistory) - check([]string{hist, "--bind=ctrl-p:accept"}, curses.CtrlP, actAccept) + check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlN, actNextHistory) + check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlP, actAccept) } func optsFor(words ...string) *Options { diff --git a/src/result.go b/src/result.go index 69e83f85..c0cf5d61 100644 --- a/src/result.go +++ b/src/result.go @@ -5,7 +5,7 @@ import ( "sort" "unicode" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" "github.com/junegunn/fzf/src/util" ) @@ -14,8 +14,8 @@ type Offset [2]int32 type colorOffset struct { offset [2]int32 - color int - attr curses.Attr + color tui.ColorPair + attr tui.Attr index int32 } @@ -92,7 +92,7 @@ func minRank() rank { return rank{index: 0, points: [4]uint16{math.MaxUint16, 0, 0, 0}} } -func (result *Result) colorOffsets(matchOffsets []Offset, theme *curses.ColorTheme, color int, attr curses.Attr, current bool) []colorOffset { +func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme, color tui.ColorPair, attr tui.Attr, current bool) []colorOffset { itemColors := result.item.Colors() // No ANSI code, or --color=no @@ -149,23 +149,23 @@ func (result *Result) colorOffsets(matchOffsets []Offset, theme *curses.ColorThe fg := ansi.color.fg if fg == -1 { if current { - fg = int(theme.Current) + fg = theme.Current } else { - fg = int(theme.Fg) + fg = theme.Fg } } bg := ansi.color.bg if bg == -1 { if current { - bg = int(theme.DarkBg) + bg = theme.DarkBg } else { - bg = int(theme.Bg) + bg = theme.Bg } } colors = append(colors, colorOffset{ offset: [2]int32{int32(start), int32(idx)}, - color: curses.PairFor(fg, bg), - attr: ansi.color.attr | attr}) + color: tui.PairFor(fg, bg), + attr: ansi.color.attr.Merge(attr)}) } } } diff --git a/src/result_test.go b/src/result_test.go index 645684dd..06402c1b 100644 --- a/src/result_test.go +++ b/src/result_test.go @@ -1,3 +1,5 @@ +// +build !termbox + package fzf import ( @@ -5,7 +7,7 @@ import ( "sort" "testing" - "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" "github.com/junegunn/fzf/src/util" ) @@ -98,26 +100,26 @@ func TestColorOffset(t *testing.T) { item: &Item{ colors: &[]ansiOffset{ ansiOffset{[2]int32{0, 20}, ansiState{1, 5, 0}}, - ansiOffset{[2]int32{22, 27}, ansiState{2, 6, curses.Bold}}, + ansiOffset{[2]int32{22, 27}, ansiState{2, 6, tui.Bold}}, ansiOffset{[2]int32{30, 32}, ansiState{3, 7, 0}}, - ansiOffset{[2]int32{33, 40}, ansiState{4, 8, curses.Bold}}}}} + ansiOffset{[2]int32{33, 40}, ansiState{4, 8, tui.Bold}}}}} // [{[0 5] 9 false} {[5 15] 99 false} {[15 20] 9 false} {[22 25] 10 true} {[25 35] 99 false} {[35 40] 11 true}] - colors := item.colorOffsets(offsets, curses.Dark256, 99, 0, true) - assert := func(idx int, b int32, e int32, c int, bold bool) { - var attr curses.Attr + colors := item.colorOffsets(offsets, tui.Dark256, 99, 0, true) + assert := func(idx int, b int32, e int32, c tui.ColorPair, bold bool) { + var attr tui.Attr if bold { - attr = curses.Bold + attr = tui.Bold } o := colors[idx] if o.offset[0] != b || o.offset[1] != e || o.color != c || o.attr != attr { t.Error(o) } } - assert(0, 0, 5, curses.ColUser, false) + assert(0, 0, 5, tui.ColUser, false) assert(1, 5, 15, 99, false) - assert(2, 15, 20, curses.ColUser, false) - assert(3, 22, 25, curses.ColUser+1, true) + assert(2, 15, 20, tui.ColUser, false) + assert(3, 22, 25, tui.ColUser+1, true) assert(4, 25, 35, 99, false) - assert(5, 35, 40, curses.ColUser+2, true) + assert(5, 35, 40, tui.ColUser+2, true) } diff --git a/src/terminal.go b/src/terminal.go index 376c6408..39c78239 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -12,7 +12,7 @@ import ( "syscall" "time" - C "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/tui" "github.com/junegunn/fzf/src/util" "github.com/junegunn/go-runewidth" @@ -69,9 +69,9 @@ type Terminal struct { header0 []string ansi bool margin [4]sizeSpec - window *C.Window - bwindow *C.Window - pwindow *C.Window + window *tui.Window + bwindow *tui.Window + pwindow *tui.Window count int progress int reading bool @@ -90,7 +90,7 @@ type Terminal struct { suppress bool startChan chan bool slab *util.Slab - theme *C.ColorTheme + theme *tui.ColorTheme } type selectedItem struct { @@ -187,51 +187,51 @@ const ( func defaultKeymap() map[int]actionType { keymap := make(map[int]actionType) - keymap[C.Invalid] = actInvalid - keymap[C.CtrlA] = actBeginningOfLine - keymap[C.CtrlB] = actBackwardChar - keymap[C.CtrlC] = actAbort - keymap[C.CtrlG] = actAbort - keymap[C.CtrlQ] = actAbort - keymap[C.ESC] = actAbort - keymap[C.CtrlD] = actDeleteCharEOF - keymap[C.CtrlE] = actEndOfLine - keymap[C.CtrlF] = actForwardChar - keymap[C.CtrlH] = actBackwardDeleteChar - keymap[C.BSpace] = actBackwardDeleteChar - keymap[C.Tab] = actToggleDown - keymap[C.BTab] = actToggleUp - keymap[C.CtrlJ] = actDown - keymap[C.CtrlK] = actUp - keymap[C.CtrlL] = actClearScreen - keymap[C.CtrlM] = actAccept - keymap[C.CtrlN] = actDown - keymap[C.CtrlP] = actUp - keymap[C.CtrlU] = actUnixLineDiscard - keymap[C.CtrlW] = actUnixWordRubout - keymap[C.CtrlY] = actYank - - keymap[C.AltB] = actBackwardWord - keymap[C.SLeft] = actBackwardWord - keymap[C.AltF] = actForwardWord - keymap[C.SRight] = actForwardWord - keymap[C.AltD] = actKillWord - keymap[C.AltBS] = actBackwardKillWord - - keymap[C.Up] = actUp - keymap[C.Down] = actDown - keymap[C.Left] = actBackwardChar - keymap[C.Right] = actForwardChar - - keymap[C.Home] = actBeginningOfLine - keymap[C.End] = actEndOfLine - keymap[C.Del] = actDeleteChar - keymap[C.PgUp] = actPageUp - keymap[C.PgDn] = actPageDown - - keymap[C.Rune] = actRune - keymap[C.Mouse] = actMouse - keymap[C.DoubleClick] = actAccept + keymap[tui.Invalid] = actInvalid + keymap[tui.CtrlA] = actBeginningOfLine + keymap[tui.CtrlB] = actBackwardChar + keymap[tui.CtrlC] = actAbort + keymap[tui.CtrlG] = actAbort + keymap[tui.CtrlQ] = actAbort + keymap[tui.ESC] = actAbort + keymap[tui.CtrlD] = actDeleteCharEOF + keymap[tui.CtrlE] = actEndOfLine + keymap[tui.CtrlF] = actForwardChar + keymap[tui.CtrlH] = actBackwardDeleteChar + keymap[tui.BSpace] = actBackwardDeleteChar + keymap[tui.Tab] = actToggleDown + keymap[tui.BTab] = actToggleUp + keymap[tui.CtrlJ] = actDown + keymap[tui.CtrlK] = actUp + keymap[tui.CtrlL] = actClearScreen + keymap[tui.CtrlM] = actAccept + keymap[tui.CtrlN] = actDown + keymap[tui.CtrlP] = actUp + keymap[tui.CtrlU] = actUnixLineDiscard + keymap[tui.CtrlW] = actUnixWordRubout + keymap[tui.CtrlY] = actYank + + keymap[tui.AltB] = actBackwardWord + keymap[tui.SLeft] = actBackwardWord + keymap[tui.AltF] = actForwardWord + keymap[tui.SRight] = actForwardWord + keymap[tui.AltD] = actKillWord + keymap[tui.AltBS] = actBackwardKillWord + + keymap[tui.Up] = actUp + keymap[tui.Down] = actDown + keymap[tui.Left] = actBackwardChar + keymap[tui.Right] = actForwardChar + + keymap[tui.Home] = actBeginningOfLine + keymap[tui.End] = actEndOfLine + keymap[tui.Del] = actDeleteChar + keymap[tui.PgUp] = actPageUp + keymap[tui.PgDn] = actPageDown + + keymap[tui.Rune] = actRune + keymap[tui.Mouse] = actMouse + keymap[tui.DoubleClick] = actAccept return keymap } @@ -299,7 +299,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { theme: opts.Theme, startChan: make(chan bool, 1), initFunc: func() { - C.Init(opts.Theme, opts.Black, opts.Mouse) + tui.Init(opts.Theme, opts.Black, opts.Mouse) }} } @@ -429,8 +429,8 @@ func calculateSize(base int, size sizeSpec, margin int, minSize int) int { } func (t *Terminal) resizeWindows() { - screenWidth := C.MaxX() - screenHeight := C.MaxY() + screenWidth := tui.MaxX() + screenHeight := tui.MaxY() marginInt := [4]int{} for idx, sizeSpec := range t.margin { if sizeSpec.percent { @@ -479,33 +479,33 @@ func (t *Terminal) resizeWindows() { height := screenHeight - marginInt[0] - marginInt[2] if t.isPreviewEnabled() { createPreviewWindow := func(y int, x int, w int, h int) { - t.bwindow = C.NewWindow(y, x, w, h, true) - t.pwindow = C.NewWindow(y+1, x+2, w-4, h-2, false) + t.bwindow = tui.NewWindow(y, x, w, h, true) + t.pwindow = tui.NewWindow(y+1, x+2, w-4, h-2, false) } switch t.preview.position { case posUp: pheight := calculateSize(height, t.preview.size, minHeight, 3) - t.window = C.NewWindow( + t.window = tui.NewWindow( marginInt[0]+pheight, marginInt[3], width, height-pheight, false) createPreviewWindow(marginInt[0], marginInt[3], width, pheight) case posDown: pheight := calculateSize(height, t.preview.size, minHeight, 3) - t.window = C.NewWindow( + t.window = tui.NewWindow( marginInt[0], marginInt[3], width, height-pheight, false) createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight) case posLeft: pwidth := calculateSize(width, t.preview.size, minWidth, 5) - t.window = C.NewWindow( + t.window = tui.NewWindow( marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false) createPreviewWindow(marginInt[0], marginInt[3], pwidth, height) case posRight: |