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
Provenance
- Commit
da3d995- Tree
75abf7f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
04c4269
2 files changed+23 added−6 removed
modified:src/terminal.go+19 added-6 removed
1799 unmodified lines1800 width, _ := util.RunesWidth(runes, 0, t.tabstop, math.MaxInt32)1801 return width1802 }1803 1804+func (t *Terminal) displayWidthWithPrefix(str string, prefixWidth int) int {1805+ width, _ := util.RunesWidth([]rune(str), prefixWidth, t.tabstop, math.MaxInt32)1806+ return width1807+}1808+1809 const (1810 minWidth = 41811 minHeight = 31812 )2958 unmodified lines4771 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 == clickHeaderLine10 unmodified lines4790 if currentLine && len(line) == 0 {4791 return env4792 }4793 4794+ // 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 line2 unmodified lines4803 }4804 }4805 4806 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)4811+4812+ 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)4815 4816 // 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 lines4838 }4839 4840 // 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)4851 4852 // 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 linesmodified:CHANGELOG.md+4 added
1 CHANGELOG2 =========3 4+0.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.7+8 0.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