Skip to content
Myr

Fix ANSI color continuation in --header

Before adoption: this commit came in with the history the project adopted, so no landing records it.

# Both lines should be in red fzf --header $'\x1b[31mfoo\nbar'

authored by Junegunn Choi · committed by Junegunn Choi · parent f834912 · Browse files · 1 file+9 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−21 removed

  • other:+9 added−21 removed

1 file+9 added−21 removed

modified:src/terminal.go+9 added-21 removed
531 unmodified lines
532533// NewTerminal returns new Terminal object534func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {535 input := trimQuery(opts.Query)536 var header []string537 switch opts.Layout {538 case layoutDefault, layoutReverseList:539 header = reverseStringArray(opts.Header)540 default:541 header = opts.Header542 }536 var delay time.Duration537 if opts.Tac {538 delay = initialDelayTac539 } else {
87 unmodified lines
627 headerVisible: true,628 headerFirst: opts.HeaderFirst,629 headerLines: opts.HeaderLines,630 header: []string{},638 header0: header,631 header0: opts.Header,632 ellipsis: opts.Ellipsis,633 ansi: opts.Ansi,634 tabstop: opts.Tabstop,635 hasLoadActions: false,
255 unmodified lines
891 t.reqBox.Set(reqRefresh, nil)892 }893}894902func reverseStringArray(input []string) []string {903 size := len(input)904 reversed := make([]string, size)905 for idx, str := range input {906 reversed[size-idx-1] = str907 }908 return reversed909}910895func (t *Terminal) changeHeader(header string) bool {896 lines := strings.Split(strings.TrimSuffix(header, "\n"), "\n")913 switch t.layout {914 case layoutDefault, layoutReverseList:915 lines = reverseStringArray(lines)916 }897 needFullRedraw := len(t.header0) != len(lines)898 t.header0 = lines899 return needFullRedraw900}
683 unmodified lines
1584 max--1585 }1586 }1587 var state *ansiState1588 needReverse := false1589 switch t.layout {1590 case layoutDefault, layoutReverseList:1591 needReverse = true1592 }1593 for idx, lineStr := range append(append([]string{}, t.header0...), t.header...) {1594 line := idx1595 if needReverse && idx < len(t.header0) {1596 line = len(t.header0) - idx - 11597 }1598 if !t.headerFirst {1599 line++1600 if !t.noInfoLine() {1601 line++
2169 unmodified lines