diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-07 01:33:42 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-07 01:34:35 +0900 |
| commit | c5fb0c43f9222e72ff00290162b68e34a8f0d5d7 (patch) | |
| tree | fa27a1ec8a6f9ce103110b0015abbb61823cf539 /src | |
| parent | 9e4780510e07a239e696c3245cd19f8754f707f2 (diff) | |
| download | fzf-c5fb0c43f9222e72ff00290162b68e34a8f0d5d7.tar.gz | |
Add --cursor-line to highlight the whole current line
Similar to 'set cursorline' of Vim.
Diffstat (limited to 'src')
| -rw-r--r-- | src/options.go | 6 | ||||
| -rw-r--r-- | src/terminal.go | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/options.go b/src/options.go index d7f2b476..fda51cba 100644 --- a/src/options.go +++ b/src/options.go @@ -92,6 +92,7 @@ const Usage = `usage: fzf [options] --ansi Enable processing of ANSI color codes --tabstop=SPACES Number of spaces for a tab character (default: 8) --color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors + --cursor-line Highlight the whole current line --no-bold Do not use bold text History @@ -322,6 +323,7 @@ type Options struct { MinHeight int Layout layoutType Cycle bool + CursorLine bool KeepRight bool Hscroll bool HscrollOff int @@ -1948,6 +1950,10 @@ func parseOptions(opts *Options, allArgs []string) error { opts.Layout = layoutDefault case "--cycle": opts.Cycle = true + case "--cursor-line": + opts.CursorLine = true + case "--no-cursor-line": + opts.CursorLine = false case "--no-cycle": opts.Cycle = false case "--keep-right": diff --git a/src/terminal.go b/src/terminal.go index 18915035..c5f718a2 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -229,6 +229,7 @@ type Terminal struct { printQuery bool history *History cycle bool + cursorLine bool headerVisible bool headerFirst bool headerLines int @@ -754,6 +755,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor executor: executor, paused: opts.Phony, cycle: opts.Cycle, + cursorLine: opts.CursorLine, headerVisible: true, headerFirst: opts.HeaderFirst, headerLines: opts.HeaderLines, @@ -1912,9 +1914,18 @@ func (t *Terminal) printItem(result Result, line int, i int, current bool, bar b } newLine.width = t.printHighlighted(result, tui.ColNormal, tui.ColMatch, false, true) } - fillSpaces := prevLine.width - newLine.width - if fillSpaces > 0 { - t.window.Print(strings.Repeat(" ", fillSpaces)) + if current && t.cursorLine { + maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1) + fillSpaces := maxWidth - newLine.width + newLine.width = maxWidth + if fillSpaces > 0 { + t.window.CPrint(tui.ColCurrent, strings.Repeat(" ", fillSpaces)) + } + } else { + fillSpaces := prevLine.width - newLine.width + if fillSpaces > 0 { + t.window.Print(strings.Repeat(" ", fillSpaces)) + } } printBar() t.prevLines[i] = newLine |
