summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-11-30 17:35:03 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-11-30 17:35:03 +0900
commit99ea1056acb622573fbb62c5b7181f3137005b3e (patch)
tree269a2e4ad1a5c1e3387233e7a10b1f5a4ea75299 /src
parent7bcf4effa54967448223b5e36a972432c1d076db (diff)
Add --tabstop option
Related: https://github.com/junegunn/fzf.vim/issues/49
Diffstat (limited to 'src')
-rw-r--r--src/options.go11
-rw-r--r--src/terminal.go4
2 files changed, 14 insertions, 1 deletions
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 {