Add --cursor-line to highlight the whole current line

Similar to 'set cursorline' of Vim.
pull/3781/head
Junegunn Choi 1 month ago
parent 9e4780510e
commit c5fb0c43f9
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -534,6 +534,9 @@ color mappings.
--color='pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99'\fR --color='pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99'\fR
.RE .RE
.TP .TP
.B "--cursor-line"
Highlight the whole current line
.TP
.B "--no-bold" .B "--no-bold"
Do not use bold text Do not use bold text
.TP .TP

@ -92,6 +92,7 @@ const Usage = `usage: fzf [options]
--ansi Enable processing of ANSI color codes --ansi Enable processing of ANSI color codes
--tabstop=SPACES Number of spaces for a tab character (default: 8) --tabstop=SPACES Number of spaces for a tab character (default: 8)
--color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors --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 --no-bold Do not use bold text
History History
@ -322,6 +323,7 @@ type Options struct {
MinHeight int MinHeight int
Layout layoutType Layout layoutType
Cycle bool Cycle bool
CursorLine bool
KeepRight bool KeepRight bool
Hscroll bool Hscroll bool
HscrollOff int HscrollOff int
@ -1948,6 +1950,10 @@ func parseOptions(opts *Options, allArgs []string) error {
opts.Layout = layoutDefault opts.Layout = layoutDefault
case "--cycle": case "--cycle":
opts.Cycle = true opts.Cycle = true
case "--cursor-line":
opts.CursorLine = true
case "--no-cursor-line":
opts.CursorLine = false
case "--no-cycle": case "--no-cycle":
opts.Cycle = false opts.Cycle = false
case "--keep-right": case "--keep-right":

@ -229,6 +229,7 @@ type Terminal struct {
printQuery bool printQuery bool
history *History history *History
cycle bool cycle bool
cursorLine bool
headerVisible bool headerVisible bool
headerFirst bool headerFirst bool
headerLines int headerLines int
@ -754,6 +755,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
executor: executor, executor: executor,
paused: opts.Phony, paused: opts.Phony,
cycle: opts.Cycle, cycle: opts.Cycle,
cursorLine: opts.CursorLine,
headerVisible: true, headerVisible: true,
headerFirst: opts.HeaderFirst, headerFirst: opts.HeaderFirst,
headerLines: opts.HeaderLines, 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) newLine.width = t.printHighlighted(result, tui.ColNormal, tui.ColMatch, false, true)
} }
fillSpaces := prevLine.width - newLine.width if current && t.cursorLine {
if fillSpaces > 0 { maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1)
t.window.Print(strings.Repeat(" ", fillSpaces)) 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() printBar()
t.prevLines[i] = newLine t.prevLines[i] = newLine

Loading…
Cancel
Save