From d0b7780239dd9f9e2bf6c252e03b463990a966bd Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 11 Jun 2023 00:04:24 +0900 Subject: Add --info=right Related: #3322 --- src/options.go | 12 ++++++++++-- src/terminal.go | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/options.go b/src/options.go index f04d7f20..87f39929 100644 --- a/src/options.go +++ b/src/options.go @@ -72,7 +72,8 @@ const usage = `usage: fzf [options] (default: 0 or center) --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L) --padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L) - --info=STYLE Finder info style [default|hidden|inline[:SEPARATOR]|inline-right] + --info=STYLE Finder info style + [default|right|hidden|inline[:SEPARATOR]|inline-right] --separator=STR String to form horizontal separator on info line --no-separator Hide info line separator --scrollbar[=C1[C2]] Scrollbar character(s) (each for main and preview window) @@ -194,11 +195,16 @@ type infoStyle int const ( infoDefault infoStyle = iota + infoRight infoInline infoInlineRight infoHidden ) +func (s infoStyle) noExtraLine() bool { + return s == infoInline || s == infoInlineRight || s == infoHidden +} + type labelOpts struct { label string column int @@ -1377,6 +1383,8 @@ func parseInfoStyle(str string) (infoStyle, string) { switch str { case "default": return infoDefault, "" + case "right": + return infoRight, "" case "inline": return infoInline, defaultInfoSep case "inline-right": @@ -1388,7 +1396,7 @@ func parseInfoStyle(str string) (infoStyle, string) { if strings.HasPrefix(str, prefix) { return infoInline, strings.ReplaceAll(str[len(prefix):], "\n", " ") } - errorExit("invalid info style (expected: default|hidden|inline[:SEPARATOR]|inline-right)") + errorExit("invalid info style (expected: default|right|hidden|inline[:SEPARATOR]|inline-right)") } return infoDefault, "" } diff --git a/src/terminal.go b/src/terminal.go index 08ea253b..94f4c6cd 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -565,7 +565,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { if previewBox != nil && opts.Preview.aboveOrBelow() { effectiveMinHeight += 1 + borderLines(opts.Preview.border) } - if opts.InfoStyle != infoDefault { + if opts.InfoStyle.noExtraLine() { effectiveMinHeight-- } effectiveMinHeight += borderLines(opts.BorderShape) @@ -845,7 +845,7 @@ func (t *Terminal) parsePrompt(prompt string) (func(), int) { } func (t *Terminal) noInfoLine() bool { - return t.infoStyle != infoDefault + return t.infoStyle.noExtraLine() } func getScrollbar(total int, height int, offset int) (int, int) { @@ -1479,6 +1479,8 @@ func (t *Terminal) printInfo() { printSpinner() t.move(line+1, 2, false) pos = 2 + case infoRight: + t.move(line+1, 0, false) case infoInlineRight: pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1 t.move(line, pos, true) @@ -1529,6 +1531,37 @@ func (t *Terminal) printInfo() { if t.failed != nil && t.count == 0 { output = fmt.Sprintf("[Command failed: %s]", *t.failed) } + + printSeparator := func(fillLength int, pad bool) { + // --------_ + if t.separatorLen > 0 { + t.separator(t.window, fillLength) + t.window.Print(" ") + } else if pad { + t.window.Print(strings.Repeat(" ", fillLength+1)) + } + } + if t.infoStyle == infoRight { + maxWidth := t.window.Width() + if t.reading { + // Need space for spinner and a margin column + maxWidth -= 2 + } + output = t.trimMessage(output, maxWidth) + fillLength := t.window.Width() - len(output) - 2 + if t.reading { + if fillLength >= 2 { + printSeparator(fillLength-2, true) + } + printSpinner() + t.window.Print(" ") + } else if fillLength >= 0 { + printSeparator(fillLength, true) + } + t.window.CPrint(tui.ColInfo, output) + return + } + if t.infoStyle == infoInlineRight { pos = util.Max(pos, t.window.Width()-util.StringWidth(output)-3) if pos >= t.window.Width() { @@ -1539,14 +1572,14 @@ func (t *Terminal) printInfo() { t.window.Print(" ") pos += 2 } + maxWidth := t.window.Width() - pos output = t.trimMessage(output, maxWidth) t.window.CPrint(tui.ColInfo, output) - fillLength := maxWidth - len(output) - 2 - if t.separatorLen > 0 && fillLength > 0 { + if fillLength > 0 { t.window.CPrint(tui.ColSeparator, " ") - t.separator(t.window, fillLength) + printSeparator(fillLength, false) } } -- cgit v1.2.3