mirror of
https://github.com/junegunn/fzf.git
synced 2026-07-22 16:10:36 +08:00
Hide default separator when a border separates input from list
- Applies when adjacent section (header, header lines, or list) draws
border line facing input section
# No separator below header border
fzf --style full --input-border none --header foo
# Separator shown; nothing separates input from list
fzf --style full --input-border none --header foo --no-header-border
- Evaluated dynamically so change-header/toggle-header update it
This commit is contained in:
@@ -3696,6 +3696,9 @@ func (opts *Options) noSeparatorLine() bool {
|
||||
if opts.Inputless {
|
||||
return true
|
||||
}
|
||||
// NOTE: This can overestimate by one line when the default separator is
|
||||
// suppressed at runtime (see Terminal.separatorLength), making the height
|
||||
// lower bounds derived from it one line more generous than necessary.
|
||||
sep := opts.Separator == nil && !opts.InputBorderShape.Visible() || opts.Separator != nil && len(*opts.Separator) > 0
|
||||
return noSeparatorLine(opts.InfoStyle, sep)
|
||||
}
|
||||
|
||||
+72
-14
@@ -271,6 +271,7 @@ type Terminal struct {
|
||||
ghost string
|
||||
separator labelPrinter
|
||||
separatorLen int
|
||||
separatorAuto bool
|
||||
spinner []string
|
||||
promptString string
|
||||
prompt func()
|
||||
@@ -1299,14 +1300,16 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
||||
}
|
||||
}
|
||||
|
||||
// Disable separator by default if input border is set
|
||||
if opts.Separator == nil && !t.inputBorderShape.Visible() || opts.Separator != nil && len(*opts.Separator) > 0 {
|
||||
bar := "─"
|
||||
if opts.Separator != nil {
|
||||
bar = *opts.Separator
|
||||
} else if !t.unicode {
|
||||
bar = "-"
|
||||
}
|
||||
// The default separator can be suppressed at runtime depending on the
|
||||
// window layout (see separatorLength)
|
||||
t.separatorAuto = opts.Separator == nil
|
||||
bar := "─"
|
||||
if opts.Separator != nil {
|
||||
bar = *opts.Separator
|
||||
} else if !t.unicode {
|
||||
bar = "-"
|
||||
}
|
||||
if len(bar) > 0 {
|
||||
t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)
|
||||
}
|
||||
|
||||
@@ -1695,7 +1698,62 @@ func (t *Terminal) parsePrompt(prompt string) (func(), int) {
|
||||
}
|
||||
|
||||
func (t *Terminal) noSeparatorLine() bool {
|
||||
return t.inputless || noSeparatorLine(t.infoStyle, t.separatorLen > 0)
|
||||
return t.inputless || noSeparatorLine(t.infoStyle, t.separatorLength() > 0)
|
||||
}
|
||||
|
||||
// Effective length of the horizontal separator. The default separator is
|
||||
// suppressed when the input section is already visually separated from the
|
||||
// list section by a border line.
|
||||
func (t *Terminal) separatorLength() int {
|
||||
if t.separatorAuto && t.separatedByBorder() {
|
||||
return 0
|
||||
}
|
||||
return t.separatorLen
|
||||
}
|
||||
|
||||
// The default horizontal separator is redundant if the input section is
|
||||
// already visually separated from the list section by a border line
|
||||
func (t *Terminal) separatedByBorder() bool {
|
||||
if t.inputBorderShape.Visible() {
|
||||
return true
|
||||
}
|
||||
hasHeaderLinesWindow, headerLinesShape := t.determineHeaderLinesShape()
|
||||
hasHeaderWindow := t.hasHeaderWindow()
|
||||
if !hasHeaderWindow && !hasHeaderLinesWindow {
|
||||
// No separate window is created for the input section in this case
|
||||
// (see hasInputWindow in resizeWindows), i.e. the input section is
|
||||
// embedded in the list window and no border separates the two
|
||||
return false
|
||||
}
|
||||
|
||||
// The input section has its own window. Determine which section it is
|
||||
// facing, and check if the border of that section draws a line toward it.
|
||||
if hasHeaderWindow && !t.headerFirst {
|
||||
// Header section
|
||||
return t.borderFacingInput(t.headerBorderShape)
|
||||
}
|
||||
// The header lines section is next to the input section, except in
|
||||
// reverse-list layout where it is on the other side of the list section,
|
||||
// or with --header-first and no header section where it is moved past the
|
||||
// input section
|
||||
if hasHeaderLinesWindow && t.layout != layoutReverseList && (hasHeaderWindow || !t.headerFirst) {
|
||||
return t.borderFacingInput(headerLinesShape)
|
||||
}
|
||||
// List section
|
||||
return t.borderFacingInput(t.listBorderShape)
|
||||
}
|
||||
|
||||
// Whether the shape draws a horizontal line facing the info line when the
|
||||
// section is placed between the input section and the list section
|
||||
func (t *Terminal) borderFacingInput(shape tui.BorderShape) bool {
|
||||
if shape == tui.BorderInline {
|
||||
// Embedded between the horizontal lines of the list border
|
||||
return true
|
||||
}
|
||||
if t.layout == layoutReverse {
|
||||
return shape.HasTop()
|
||||
}
|
||||
return shape.HasBottom()
|
||||
}
|
||||
|
||||
func getScrollbar(perLine int, total int, height int, offset int) (int, int) {
|
||||
@@ -3357,7 +3415,7 @@ func (t *Terminal) printInfoImpl() {
|
||||
str = string(trimmed)
|
||||
width = maxWidth
|
||||
}
|
||||
move(line, pos, t.separatorLen == 0)
|
||||
move(line, pos, t.separatorLength() == 0)
|
||||
if t.reading {
|
||||
t.window.CPrint(tui.ColSpinner, str)
|
||||
} else {
|
||||
@@ -3366,7 +3424,7 @@ func (t *Terminal) printInfoImpl() {
|
||||
pos += width
|
||||
}
|
||||
printSeparator := func(fillLength int, pad bool) {
|
||||
if t.separatorLen > 0 {
|
||||
if t.separatorLength() > 0 {
|
||||
t.separator(t.window, fillLength)
|
||||
t.window.Print(" ")
|
||||
} else if pad {
|
||||
@@ -3375,7 +3433,7 @@ func (t *Terminal) printInfoImpl() {
|
||||
}
|
||||
|
||||
if t.infoStyle == infoHidden {
|
||||
if t.separatorLen > 0 {
|
||||
if t.separatorLength() > 0 {
|
||||
if !move(line+1, 0, false) {
|
||||
return
|
||||
}
|
||||
@@ -3438,7 +3496,7 @@ func (t *Terminal) printInfoImpl() {
|
||||
}
|
||||
switch t.infoStyle {
|
||||
case infoDefault:
|
||||
if !move(line+1, 0, t.separatorLen == 0) {
|
||||
if !move(line+1, 0, t.separatorLength() == 0) {
|
||||
return
|
||||
}
|
||||
printSpinner()
|
||||
@@ -3522,7 +3580,7 @@ func (t *Terminal) printInfoImpl() {
|
||||
}
|
||||
|
||||
if t.infoStyle == infoInlineRight {
|
||||
if t.separatorLen > 0 {
|
||||
if t.separatorLength() > 0 {
|
||||
if !move(line+1, 0, false) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user