summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-03-02 03:06:21 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-03-02 03:14:35 +0900
commit2ccdf21a1fa0ce64123fe89e1b7931240420e8e6 (patch)
tree260774a46cd3154e12a9de337777abffc79f520b /src
parentcf8afc527e27600ac9f91127c57f24a9c6727b6c (diff)
downloadfzf-2ccdf21a1fa0ce64123fe89e1b7931240420e8e6.tar.gz
Add --hscroll-off=COL option
Close #513
Diffstat (limited to 'src')
-rw-r--r--src/options.go12
-rw-r--r--src/terminal.go9
-rw-r--r--src/util/util.go8
3 files changed, 25 insertions, 4 deletions
diff --git a/src/options.go b/src/options.go
index 723c7fc6..dfd9a1b6 100644
--- a/src/options.go
+++ b/src/options.go
@@ -42,6 +42,8 @@ const usage = `usage: fzf [options]
--tabstop=SPACES Number of spaces for a tab character (default: 8)
--cycle Enable cyclic scroll
--no-hscroll Disable horizontal scroll
+ --hscroll-off=COL Number of screen columns to keep to the right of the
+ highlighted substring (default: 10)
--inline-info Display finder info inline with the query
--prompt=STR Input prompt (default: '> ')
--bind=KEYBINDS Custom key bindings. Refer to the man page.
@@ -108,6 +110,7 @@ type Options struct {
Reverse bool
Cycle bool
Hscroll bool
+ HscrollOff int
InlineInfo bool
Prompt string
Query string
@@ -155,6 +158,7 @@ func defaultOptions() *Options {
Reverse: false,
Cycle: false,
Hscroll: true,
+ HscrollOff: 10,
InlineInfo: false,
Prompt: "> ",
Query: "",
@@ -795,6 +799,8 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Hscroll = true
case "--no-hscroll":
opts.Hscroll = false
+ case "--hscroll-off":
+ opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")
case "--inline-info":
opts.InlineInfo = true
case "--no-inline-info":
@@ -884,6 +890,8 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Margin = parseMargin(value)
} else if match, value := optString(arg, "--tabstop="); match {
opts.Tabstop = atoi(value)
+ } else if match, value := optString(arg, "--hscroll-off="); match {
+ opts.HscrollOff = atoi(value)
} else {
errorExit("unknown option: " + arg)
}
@@ -894,6 +902,10 @@ func parseOptions(opts *Options, allArgs []string) {
errorExit("header lines must be a non-negative integer")
}
+ if opts.HscrollOff < 0 {
+ errorExit("hscroll offset must be a non-negative integer")
+ }
+
if opts.Tabstop < 1 {
errorExit("tab stop must be a positive integer")
}
diff --git a/src/terminal.go b/src/terminal.go
index 3c6f47c6..d95cfad3 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -26,6 +26,7 @@ type Terminal struct {
prompt string
reverse bool
hscroll bool
+ hscrollOff int
cx int
cy int
offset int
@@ -210,6 +211,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
prompt: opts.Prompt,
reverse: opts.Reverse,
hscroll: opts.Hscroll,
+ hscrollOff: opts.HscrollOff,
cx: len(input),
cy: 0,
offset: 0,
@@ -556,11 +558,9 @@ func trimLeft(runes []rune, width int) ([]rune, int32) {
}
func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
- var maxe int32
+ var maxe int
for _, offset := range item.offsets {
- if offset[1] > maxe {
- maxe = offset[1]
- }
+ maxe = util.Max(maxe, int(offset[1]))
}
// Overflow
@@ -568,6 +568,7 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
copy(text, item.text)
offsets := item.colorOffsets(col2, bold, current)
maxWidth := C.MaxX() - 3 - t.marginInt[1] - t.marginInt[3]
+ maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))
fullWidth := displayWidth(text)
if fullWidth > maxWidth {
if t.hscroll {
diff --git a/src/util/util.go b/src/util/util.go
index ab9e7664..4f3d409d 100644
--- a/src/util/util.go
+++ b/src/util/util.go
@@ -21,6 +21,14 @@ func Max(first int, items ...int) int {
return max
}
+// Min returns the smallest integer
+func Min(first int, second int) int {
+ if first <= second {
+ return first
+ }
+ return second
+}
+
// Min32 returns the smallest 32-bit integer
func Min32(first int32, second int32) int32 {
if first <= second {