Skip to content
Myr

Fix $FZF_CLICK_{HEADER,FOOTER}_WORD with ANSI colors and tabs

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 04c4269 · Browse files · 2 files+23 added−6 removed
This commit

State

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

Diff stats

2 files+23 added−6 removed

  • other:+23 added−6 removed

2 files+23 added−6 removed

modified:src/terminal.go+19 added-6 removed
1799 unmodified lines
1800 width, _ := util.RunesWidth(runes, 0, t.tabstop, math.MaxInt32)1801 return width1802}18031804func (t *Terminal) displayWidthWithPrefix(str string, prefixWidth int) int {1805 width, _ := util.RunesWidth([]rune(str), prefixWidth, t.tabstop, math.MaxInt32)1806 return width1807}18081809const (1810 minWidth = 41811 minHeight = 31812)
2958 unmodified lines
4771 headers := [2][]string{t.header, t.header0}4772 if t.layout == layoutReverse {4773 headers[0], headers[1] = headers[1], headers[0]4774 }4775 var trimmedLine string4776 var words []Token4777 var lineNum int4778 for lineNum = 0; lineNum <= clickHeaderLine; lineNum++ {4779 currentLine := lineNum == clickHeaderLine
10 unmodified lines
4790 if currentLine && len(line) == 0 {4791 return env4792 }47934794 // NOTE: We can't expand tabs here because the delimiter can contain tabs.4795 trimmedLine, _, _ = extractColor(line, nil, nil)4788 words = Tokenize(line, t.delimiter)4796 words = Tokenize(trimmedLine, t.delimiter)4797 if currentLine {4798 break4799 } else {4800 // TODO: Counting can be incorrect when the delimiter contains new line
2 unmodified lines
4803 }4804 }48054806 colNum := t.clickHeaderColumn - 14807 prefixWidth, prefixLength := 0, 04808 for idx, token := range words {4800 prefixWidth := int(token.prefixLength)4801 word := token.text.ToString()4809 prefixWidth += t.displayWidthWithPrefix(trimmedLine[prefixLength:token.prefixLength], prefixWidth)4810 prefixLength = int(token.prefixLength)48114812 word, _ := t.processTabs(token.text.ToRunes(), prefixWidth)4813 trimmed := strings.TrimRightFunc(word, unicode.IsSpace)4803 trimWidth, _ := util.RunesWidth([]rune(trimmed), prefixWidth, t.tabstop, math.MaxInt32)4814 trimWidth := t.displayWidthWithPrefix(trimmed, prefixWidth)48154816 // Find the position of the first non-space character in the word4817 minPos := strings.IndexFunc(trimmed, func(r rune) bool {4818 return !unicode.IsSpace(r)
19 unmodified lines
4838 }48394840 // NOTE: Unlike in click-header, we don't use --delimiter here, since we're4841 // only interested in the word, not nth. Does this make sense?4842 trimmed, _, _ := extractColor(t.footer[clickFooterLine], nil, nil)4843 trimmed, _ = t.processTabs([]rune(trimmed), 0)4831 words := Tokenize(t.footer[clickFooterLine], Delimiter{})4844 words := Tokenize(trimmed, Delimiter{})4845 colNum := t.clickFooterColumn - 14846 for _, token := range words {4847 prefixWidth := int(token.prefixLength)4848 word := token.text.ToString()4849 trimmed := strings.TrimRightFunc(word, unicode.IsSpace)4837 trimWidth, _ := util.RunesWidth([]rune(trimmed), prefixWidth, t.tabstop, math.MaxInt32)4850 trimWidth := t.displayWidthWithPrefix(trimmed, prefixWidth)48514852 // Find the position of the first non-space character in the word4853 minPos := strings.IndexFunc(trimmed, func(r rune) bool {4854 return !unicode.IsSpace(r)
2159 unmodified lines
modified:CHANGELOG.md+4 added
1CHANGELOG2=========340.65.15------6- Fixed incorrect `$FZF_CLICK_HEADER_WORD` and `$FZF_CLICK_FOOTER_WORD` when the header or footer contains ANSI escape sequences and tab characters.780.65.09------10- Added `click-footer` event that is triggered when the footer section is clicked. When the event is triggered, the following environment variables are set:11 - `$FZF_CLICK_FOOTER_COLUMN` - clicked column (1-based)
2774 unmodified lines