diff --git a/CHANGELOG.md b/CHANGELOG.md index 7381354d..b1f4b70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +0.11.1 +------ + +- Added `--tabstop=SPACES` option + 0.11.0 ------ diff --git a/src/options.go b/src/options.go index 169b1055..ad05213c 100644 --- a/src/options.go +++ b/src/options.go @@ -38,6 +38,7 @@ const usage = `usage: fzf [options] --black Use black background --reverse Reverse orientation --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L) + --tabstop=SPACES Number of spaces for a tab character (default: 8) --cycle Enable cyclic scroll --no-hscroll Disable horizontal scroll --inline-info Display finder info inline with the query @@ -123,6 +124,7 @@ type Options struct { Header []string HeaderLines int Margin [4]string + Tabstop int Version bool } @@ -169,6 +171,7 @@ func defaultOptions() *Options { Header: make([]string, 0), HeaderLines: 0, Margin: defaultMargin(), + Tabstop: 8, Version: false} } @@ -822,6 +825,8 @@ func parseOptions(opts *Options, allArgs []string) { case "--margin": opts.Margin = parseMargin( nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)")) + case "--tabstop": + opts.Tabstop = nextInt(allArgs, &i, "tab stop required") case "--version": opts.Version = true default: @@ -861,6 +866,8 @@ func parseOptions(opts *Options, allArgs []string) { opts.HeaderLines = atoi(value) } else if match, value := optString(arg, "--margin="); match { opts.Margin = parseMargin(value) + } else if match, value := optString(arg, "--tabstop="); match { + opts.Tabstop = atoi(value) } else { errorExit("unknown option: " + arg) } @@ -871,6 +878,10 @@ func parseOptions(opts *Options, allArgs []string) { errorExit("header lines must be a non-negative integer") } + if opts.Tabstop < 1 { + errorExit("tab stop must be a positive integer") + } + // Change default actions for CTRL-N / CTRL-P when --history is used if opts.History != nil { if _, prs := keymap[curses.CtrlP]; !prs { diff --git a/src/terminal.go b/src/terminal.go index 764459ff..a19f41d8 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -80,6 +80,7 @@ func (a byTimeOrder) Less(i, j int) bool { var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`} var _runeWidths = make(map[rune]int) +var _tabStop int const ( reqPrompt util.EventType = iota @@ -194,6 +195,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { } else { header = reverseStringArray(opts.Header) } + _tabStop = opts.Tabstop return &Terminal{ inlineInfo: opts.InlineInfo, prompt: opts.Prompt, @@ -324,7 +326,7 @@ func (t *Terminal) sortSelected() []selectedItem { func runeWidth(r rune, prefixWidth int) int { if r == '\t' { - return 8 - prefixWidth%8 + return _tabStop - prefixWidth%_tabStop } else if w, found := _runeWidths[r]; found { return w } else { diff --git a/test/test_go.rb b/test/test_go.rb index 275e1204..f36f98b2 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -866,6 +866,26 @@ class TestGoFZF < TestBase tmux.send_keys :Enter end + def test_tabstop + writelines tempname, ["f\too\tba\tr\tbaz\tbarfooq\tux"] + { + 1 => '> f oo ba r baz barfooq ux', + 2 => '> f oo ba r baz barfooq ux', + 3 => '> f oo ba r baz barfooq ux', + 4 => '> f oo ba r baz barfooq ux', + 5 => '> f oo ba r baz barfooq ux', + 6 => '> f oo ba r baz barfooq ux', + 7 => '> f oo ba r baz barfooq ux', + 8 => '> f oo ba r baz barfooq ux', + 9 => '> f oo ba r baz barfooq ux', + }.each do |ts, exp| + tmux.prepare + tmux.send_keys %[cat #{tempname} | fzf --tabstop=#{ts}], :Enter + tmux.until { |lines| lines[-3] == exp } + tmux.send_keys :Enter + end + end + def test_with_nth writelines tempname, ['hello world ', 'byebye'] assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp