summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-03-11 22:35:24 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-03-11 22:35:24 +0900
commit373c6d8d55066251dc7af58598de6af4ff4570cf (patch)
tree64ee23a2408245aba56f5e3d07a08b3e17c98ad8 /src
parentb8fc828955176f18a94630f2ad4d28c54aa6c927 (diff)
downloadfzf-373c6d8d55066251dc7af58598de6af4ff4570cf.tar.gz
Add --keep-right option to keep the right end of the line visible
Close #1652
Diffstat (limited to 'src')
-rw-r--r--src/options.go7
-rw-r--r--src/terminal.go19
2 files changed, 20 insertions, 6 deletions
diff --git a/src/options.go b/src/options.go
index 0fd97050..32c50af5 100644
--- a/src/options.go
+++ b/src/options.go
@@ -44,6 +44,7 @@ const usage = `usage: fzf [options]
--no-mouse Disable mouse
--bind=KEYBINDS Custom key bindings. Refer to the man page.
--cycle Enable cyclic scroll
+ --keep-right Keep the right end of the line visible on overflow
--no-hscroll Disable horizontal scroll
--hscroll-off=COL Number of screen columns to keep to the right of the
highlighted substring (default: 10)
@@ -187,6 +188,7 @@ type Options struct {
MinHeight int
Layout layoutType
Cycle bool
+ KeepRight bool
Hscroll bool
HscrollOff int
FileWord bool
@@ -242,6 +244,7 @@ func defaultOptions() *Options {
MinHeight: 10,
Layout: layoutDefault,
Cycle: false,
+ KeepRight: false,
Hscroll: true,
HscrollOff: 10,
FileWord: false,
@@ -1174,6 +1177,10 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Cycle = true
case "--no-cycle":
opts.Cycle = false
+ case "--keep-right":
+ opts.KeepRight = true
+ case "--no-keep-right":
+ opts.KeepRight = false
case "--hscroll":
opts.Hscroll = true
case "--no-hscroll":
diff --git a/src/terminal.go b/src/terminal.go
index a6a5c5ba..0cb45c90 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -25,6 +25,8 @@ import (
var placeholder *regexp.Regexp
var activeTempFiles []string
+const ellipsis string = ".."
+
func init() {
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)
activeTempFiles = []string{}
@@ -73,6 +75,7 @@ type Terminal struct {
queryLen [2]int
layout layoutType
fullscreen bool
+ keepRight bool
hscroll bool
hscrollOff int
wordRubout string
@@ -397,6 +400,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
queryLen: [2]int{0, 0},
layout: opts.Layout,
fullscreen: fullscreen,
+ keepRight: opts.KeepRight,
hscroll: opts.Hscroll,
hscrollOff: opts.HscrollOff,
wordRubout: wordRubout,
@@ -1000,14 +1004,17 @@ func (t *Terminal) printHighlighted(result Result, attr tui.Attr, col1 tui.Color
displayWidth := t.displayWidthWithLimit(text, 0, maxWidth)
if displayWidth > maxWidth {
if t.hscroll {
- // Stri..
- if !t.overflow(text[:maxe], maxWidth-2) {
+ if t.keepRight && pos == nil {
+ text, _ = t.trimLeft(text, maxWidth-2)
+ text = append([]rune(ellipsis), text...)
+ } else if !t.overflow(text[:maxe], maxWidth-2) {
+ // Stri..
text, _ = t.trimRight(text, maxWidth-2)
- text = append(text, []rune("..")...)
+ text = append(text, []rune(ellipsis)...)
} else {
// Stri..
if t.overflow(text[maxe:], 2) {
- text = append(text[:maxe], []rune("..")...)
+ text = append(text[:maxe], []rune(ellipsis)...)
}
// ..ri..
var diff int32
@@ -1022,11 +1029,11 @@ func (t *Terminal) printHighlighted(result Result, attr tui.Attr, col1 tui.Color
offsets[idx].offset[0] = b
offsets[idx].offset[1] = util.Max32(b, e)
}
- text = append([]rune(".."), text...)
+ text = append([]rune(ellipsis), text...)
}
} else {
text, _ = t.trimRight(text, maxWidth-2)
- text = append(text, []rune("..")...)
+ text = append(text, []rune(ellipsis)...)
for idx, offset := range offsets {
offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-2))