mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-29 08:13:54 +00:00
Add --tabstop option
Related: https://github.com/junegunn/fzf.vim/issues/49
This commit is contained in:
parent
7bcf4effa5
commit
99ea1056ac
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.11.1
|
||||||
|
------
|
||||||
|
|
||||||
|
- Added `--tabstop=SPACES` option
|
||||||
|
|
||||||
0.11.0
|
0.11.0
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ const usage = `usage: fzf [options]
|
|||||||
--black Use black background
|
--black Use black background
|
||||||
--reverse Reverse orientation
|
--reverse Reverse orientation
|
||||||
--margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)
|
--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
|
--cycle Enable cyclic scroll
|
||||||
--no-hscroll Disable horizontal scroll
|
--no-hscroll Disable horizontal scroll
|
||||||
--inline-info Display finder info inline with the query
|
--inline-info Display finder info inline with the query
|
||||||
@ -123,6 +124,7 @@ type Options struct {
|
|||||||
Header []string
|
Header []string
|
||||||
HeaderLines int
|
HeaderLines int
|
||||||
Margin [4]string
|
Margin [4]string
|
||||||
|
Tabstop int
|
||||||
Version bool
|
Version bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +171,7 @@ func defaultOptions() *Options {
|
|||||||
Header: make([]string, 0),
|
Header: make([]string, 0),
|
||||||
HeaderLines: 0,
|
HeaderLines: 0,
|
||||||
Margin: defaultMargin(),
|
Margin: defaultMargin(),
|
||||||
|
Tabstop: 8,
|
||||||
Version: false}
|
Version: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,6 +825,8 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
case "--margin":
|
case "--margin":
|
||||||
opts.Margin = parseMargin(
|
opts.Margin = parseMargin(
|
||||||
nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)"))
|
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":
|
case "--version":
|
||||||
opts.Version = true
|
opts.Version = true
|
||||||
default:
|
default:
|
||||||
@ -861,6 +866,8 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.HeaderLines = atoi(value)
|
opts.HeaderLines = atoi(value)
|
||||||
} else if match, value := optString(arg, "--margin="); match {
|
} else if match, value := optString(arg, "--margin="); match {
|
||||||
opts.Margin = parseMargin(value)
|
opts.Margin = parseMargin(value)
|
||||||
|
} else if match, value := optString(arg, "--tabstop="); match {
|
||||||
|
opts.Tabstop = atoi(value)
|
||||||
} else {
|
} else {
|
||||||
errorExit("unknown option: " + arg)
|
errorExit("unknown option: " + arg)
|
||||||
}
|
}
|
||||||
@ -871,6 +878,10 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
errorExit("header lines must be a non-negative integer")
|
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
|
// Change default actions for CTRL-N / CTRL-P when --history is used
|
||||||
if opts.History != nil {
|
if opts.History != nil {
|
||||||
if _, prs := keymap[curses.CtrlP]; !prs {
|
if _, prs := keymap[curses.CtrlP]; !prs {
|
||||||
|
@ -80,6 +80,7 @@ func (a byTimeOrder) Less(i, j int) bool {
|
|||||||
|
|
||||||
var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}
|
var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}
|
||||||
var _runeWidths = make(map[rune]int)
|
var _runeWidths = make(map[rune]int)
|
||||||
|
var _tabStop int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
reqPrompt util.EventType = iota
|
reqPrompt util.EventType = iota
|
||||||
@ -194,6 +195,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
} else {
|
} else {
|
||||||
header = reverseStringArray(opts.Header)
|
header = reverseStringArray(opts.Header)
|
||||||
}
|
}
|
||||||
|
_tabStop = opts.Tabstop
|
||||||
return &Terminal{
|
return &Terminal{
|
||||||
inlineInfo: opts.InlineInfo,
|
inlineInfo: opts.InlineInfo,
|
||||||
prompt: opts.Prompt,
|
prompt: opts.Prompt,
|
||||||
@ -324,7 +326,7 @@ func (t *Terminal) sortSelected() []selectedItem {
|
|||||||
|
|
||||||
func runeWidth(r rune, prefixWidth int) int {
|
func runeWidth(r rune, prefixWidth int) int {
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
return 8 - prefixWidth%8
|
return _tabStop - prefixWidth%_tabStop
|
||||||
} else if w, found := _runeWidths[r]; found {
|
} else if w, found := _runeWidths[r]; found {
|
||||||
return w
|
return w
|
||||||
} else {
|
} else {
|
||||||
|
@ -866,6 +866,26 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
end
|
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
|
def test_with_nth
|
||||||
writelines tempname, ['hello world ', 'byebye']
|
writelines tempname, ['hello world ', 'byebye']
|
||||||
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
||||||
|
Loading…
Reference in New Issue
Block a user