mirror of
https://github.com/junegunn/fzf.git
synced 2026-08-05 23:48:36 +08:00
Fix inline header/footer border color when falling back to line
InitTheme was called before the runtime coerced BorderInline to BorderLine, so HeaderBorder / FooterBorder inherited from ListBorder even when the effective shape was 'line'. Mirror the coercion so color inheritance matches the rendered shape.
This commit is contained in:
+7
-3
@@ -1167,10 +1167,14 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
|||||||
if baseTheme == nil {
|
if baseTheme == nil {
|
||||||
baseTheme = renderer.DefaultTheme()
|
baseTheme = renderer.DefaultTheme()
|
||||||
}
|
}
|
||||||
// This should be called before accessing tui.Color*
|
// If the list border can't host an inline separator, the runtime later coerces
|
||||||
headerInline := opts.HeaderBorderShape == tui.BorderInline || opts.HeaderLinesShape == tui.BorderInline
|
// BorderInline to BorderLine. Mirror that here so theme color inheritance matches
|
||||||
footerInline := opts.FooterBorderShape == tui.BorderInline
|
// the final rendering rather than the user's requested shape.
|
||||||
|
inlineListSupported := opts.ListBorderShape.HasTop() && opts.ListBorderShape.HasBottom()
|
||||||
|
headerInline := inlineListSupported && (opts.HeaderBorderShape == tui.BorderInline || opts.HeaderLinesShape == tui.BorderInline)
|
||||||
|
footerInline := inlineListSupported && opts.FooterBorderShape == tui.BorderInline
|
||||||
hasHeader := opts.HeaderBorderShape.Visible() || opts.HeaderLinesShape.Visible()
|
hasHeader := opts.HeaderBorderShape.Visible() || opts.HeaderLinesShape.Visible()
|
||||||
|
// This should be called before accessing tui.Color*
|
||||||
tui.InitTheme(opts.Theme, baseTheme, opts.Bold, opts.Black, opts.InputBorderShape.Visible(), hasHeader, headerInline, footerInline)
|
tui.InitTheme(opts.Theme, baseTheme, opts.Bold, opts.Black, opts.InputBorderShape.Visible(), hasHeader, headerInline, footerInline)
|
||||||
|
|
||||||
// Gutter character
|
// Gutter character
|
||||||
|
|||||||
@@ -130,6 +130,11 @@ class Tmux
|
|||||||
go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse
|
go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raw pane capture with ANSI escape sequences preserved.
|
||||||
|
def capture_ansi
|
||||||
|
go(%W[capture-pane -p -J -e -t #{win}])
|
||||||
|
end
|
||||||
|
|
||||||
# 3-bit ANSI bg code (40..47) -> color name used in --color options.
|
# 3-bit ANSI bg code (40..47) -> color name used in --color options.
|
||||||
BG_NAMES = %w[black red green yellow blue magenta cyan white].freeze
|
BG_NAMES = %w[black red green yellow blue magenta cyan white].freeze
|
||||||
|
|
||||||
|
|||||||
@@ -1466,6 +1466,31 @@ class TestLayout < TestInteractive
|
|||||||
tmux.send_keys 'Escape'
|
tmux.send_keys 'Escape'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Regression: when --header-border=inline falls back to `line` because the
|
||||||
|
# list border can't host an inline separator, the header-border color must
|
||||||
|
# inherit from `border`, not `list-border`. The effective shape is `line`,
|
||||||
|
# so color inheritance must match what `line` rendering would use.
|
||||||
|
def test_inline_fallback_does_not_inherit_list_border_color
|
||||||
|
# Marker attribute (bold) on list-border. If HeaderBorder wrongly inherits
|
||||||
|
# from ListBorder, the header separator characters will carry the bold
|
||||||
|
# attribute. --info=hidden and --no-separator strip other separator lines
|
||||||
|
# so the only row of `─` chars is the header separator.
|
||||||
|
tmux.send_keys %(seq 5 | #{FZF} --list-border=none --header HEADER --header-border=inline --info=hidden --no-separator --color=bg:-1,list-border:red:bold), :Enter
|
||||||
|
sep_row = nil
|
||||||
|
tmux.until do |_|
|
||||||
|
sep_row = tmux.capture_ansi.find do |row|
|
||||||
|
stripped = row.gsub(/\e\[[\d;]*m/, '').rstrip
|
||||||
|
stripped.match?(/\A─+\z/)
|
||||||
|
end
|
||||||
|
!sep_row.nil?
|
||||||
|
end
|
||||||
|
# Bold (1) or red fg (31) on the header separator means it inherited from
|
||||||
|
# list-border even though the effective shape is `line` (non-inline).
|
||||||
|
refute_match(/\e\[(?:[\d;]*;)?(?:1|31)(?:;[\d;]*)?m─/, sep_row,
|
||||||
|
"header separator inherited list-border attr: #{sep_row.inspect}")
|
||||||
|
tmux.send_keys 'Escape'
|
||||||
|
end
|
||||||
|
|
||||||
# Invalid inline combinations must be rejected at startup.
|
# Invalid inline combinations must be rejected at startup.
|
||||||
def test_inline_rejected_on_unsupported_options
|
def test_inline_rejected_on_unsupported_options
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user