Skip to content
Myr

Add --ellipsis=.. option

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

Close #2432 Also see - #1769 - https://github.com/junegunn/fzf/pull/1844#issuecomment-586663660

authored by Junegunn Choi · committed by Junegunn Choi · parent b88eb72 · Browse files · 8 files+97 added−22 removed
This commit

State

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

Diff stats

8 files+97 added−22 removed

  • tests:+6 added−0 removed
  • other:+91 added−22 removed

8 files+97 added−22 removed

modified:man/man1/fzf-tmux.1+1 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf-tmux 1 "Dec 2021" "fzf 0.29.0" "fzf-tmux - open fzf in tmux split pane"24.TH fzf-tmux 1 "Mar 2022" "fzf 0.30.0" "fzf-tmux - open fzf in tmux split pane"2526.SH NAME27fzf-tmux - open fzf in tmux split pane28
40 unmodified lines
modified:man/man1/fzf.1+4 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Dec 2021" "fzf 0.29.0" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Mar 2022" "fzf 0.30.0" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
272 unmodified lines
301lines that follow.302.TP303.B "--header-first"304Print header before the prompt line305.TP306.BI "--ellipsis=" "STR"307Ellipsis to show when line is truncated (default: '..')308.SS Display309.TP310.B "--ansi"311Enable processing of ANSI color codes
710 unmodified lines
modified:src/util/util_test.go+10 added
52 unmodified lines
53 t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx)54 }55 }56}5758func TestTruncate(t *testing.T) {59 truncated, width := Truncate("가나다라마", 7)60 if string(truncated) != "가나다" {61 t.Errorf("Expected: 가나다, actual: %s", string(truncated))62 }63 if width != 6 {64 t.Errorf("Expected: 6, actual: %d", width)65 }66}
modified:src/util/util.go+17 added
32 unmodified lines
33 }34 return width, -135}3637// Truncate returns the truncated runes and its width38func Truncate(input string, limit int) ([]rune, int) {39 runes := []rune{}40 width := 041 gr := uniseg.NewGraphemes(input)42 for gr.Next() {43 rs := gr.Runes()44 w := runewidth.StringWidth(string(rs))45 if width+w > limit {46 return runes, width47 }48 width += w49 runes = append(runes, rs...)50 }51 return runes, width52}5354// Max returns the largest integer55func Max(first int, second int) int {56 if first >= second {57 return first
98 unmodified lines
modified:src/options.go+18 added
68 unmodified lines
69 --marker=STR Multi-select marker (default: '>')70 --header=STR String to print as header71 --header-lines=N The first N lines of the input are treated as header72 --header-first Print header before the prompt line73 --ellipsis=STR Ellipsis to show when line is truncated (default: '..')7475 Display76 --ansi Enable processing of ANSI color codes77 --tabstop=SPACES Number of spaces for a tab character (default: 8)
157 unmodified lines
235 History *History236 Header []string237 HeaderLines int238 HeaderFirst bool239 Ellipsis string240 Margin [4]sizeSpec241 Padding [4]sizeSpec242 BorderShape tui.BorderShape243 Unicode bool
55 unmodified lines
299 History: nil,300 Header: make([]string, 0),301 HeaderLines: 0,302 HeaderFirst: false,303 Ellipsis: "..",304 Margin: defaultMargin(),305 Padding: defaultMargin(),306 Unicode: true,307 Tabstop: 8,
974 unmodified lines
1282 }1283 validateJumpLabels := false1284 validatePointer := false1285 validateMarker := false1286 validateEllipsis := false1287 for i := 0; i < len(allArgs); i++ {1288 arg := allArgs[i]1289 switch arg {1290 case "-h", "--help":
177 unmodified lines
1468 case "--header-first":1469 opts.HeaderFirst = true1470 case "--no-header-first":1471 opts.HeaderFirst = false1472 case "--ellipsis":1473 opts.Ellipsis = nextString(allArgs, &i, "ellipsis string required")1474 validateEllipsis = true1475 case "--preview":1476 opts.Preview.command = nextString(allArgs, &i, "preview command required")1477 case "--no-preview":1478 opts.Preview.command = ""
89 unmodified lines
1568 } else if match, value := optString(arg, "--header="); match {1569 opts.Header = strLines(value)1570 } else if match, value := optString(arg, "--header-lines="); match {1571 opts.HeaderLines = atoi(value)1572 } else if match, value := optString(arg, "--ellipsis="); match {1573 opts.Ellipsis = value1574 validateEllipsis = true1575 } else if match, value := optString(arg, "--preview="); match {1576 opts.Preview.command = value1577 } else if match, value := optString(arg, "--preview-window="); match {1578 parsePreviewWindow(&opts.Preview, value)
54 unmodified lines
1633 if err := validateSign(opts.Marker, "marker"); err != nil {1634 errorExit(err.Error())1635 }1636 }16371638 if validateEllipsis {1639 for _, r := range opts.Ellipsis {1640 if !unicode.IsGraphic(r) {1641 errorExit("invalid character in ellipsis")1642 }1643 }1644 }1645}16461647func validateSign(sign string, signOptName string) error {1648 if sign == "" {
104 unmodified lines
modified:src/terminal.go+28 added-20 removed
48 unmodified lines
49var offsetComponentRegex *regexp.Regexp50var offsetTrimCharsRegex *regexp.Regexp51var activeTempFiles []string5253const ellipsis string = ".."53const clearCode string = "\x1b[2J"5455func init() {56 placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)
86 unmodified lines
143 headerFirst bool144 headerLines int145 header []string146 header0 []string147 ellipsis string148 ansi bool149 tabstop int150 margin [4]sizeSpec151 padding [4]sizeSpec
388 unmodified lines
540 headerFirst: opts.HeaderFirst,541 headerLines: opts.HeaderLines,542 header: header,543 header0: header,544 ellipsis: opts.Ellipsis,545 ansi: opts.Ansi,546 tabstop: opts.Tabstop,547 reading: true,548 running: true,
712 unmodified lines
1261 }12621263 offsets := result.colorOffsets(charOffsets, t.theme, colBase, colMatch, current)1264 maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1)1265 ellipsis, ellipsisWidth := util.Truncate(t.ellipsis, maxWidth/2)1264 maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))1266 maxe = util.Constrain(maxe+util.Min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(text))1267 displayWidth := t.displayWidthWithLimit(text, 0, maxWidth)1268 if displayWidth > maxWidth {1267 transformOffsets := func(diff int32) {1269 transformOffsets := func(diff int32, rightTrim bool) {1270 for idx, offset := range offsets {1271 b, e := offset.offset[0], offset.offset[1]1272 el := int32(len(ellipsis))1270 b += 2 - diff1271 e += 2 - diff1272 b = util.Max32(b, 2)1273 b += el - diff1274 e += el - diff1275 b = util.Max32(b, el)1276 if rightTrim {1277 e = util.Min32(e, int32(maxWidth-ellipsisWidth))1278 }1279 offsets[idx].offset[0] = b1280 offsets[idx].offset[1] = util.Max32(b, e)1281 }1282 }1283 if t.hscroll {1284 if t.keepRight && pos == nil {1279 trimmed, diff := t.trimLeft(text, maxWidth-2)1280 transformOffsets(diff)1281 text = append([]rune(ellipsis), trimmed...)1282 } else if !t.overflow(text[:maxe], maxWidth-2) {1285 trimmed, diff := t.trimLeft(text, maxWidth-ellipsisWidth)1286 transformOffsets(diff, false)1287 text = append(ellipsis, trimmed...)1288 } else if !t.overflow(text[:maxe], maxWidth-ellipsisWidth) {1289 // Stri..1284 text, _ = t.trimRight(text, maxWidth-2)1285 text = append(text, []rune(ellipsis)...)1290 text, _ = t.trimRight(text, maxWidth-ellipsisWidth)1291 text = append(text, ellipsis...)1292 } else {1293 // Stri..1294 rightTrim := false1288 if t.overflow(text[maxe:], 2) {1289 text = append(text[:maxe], []rune(ellipsis)...)1295 if t.overflow(text[maxe:], ellipsisWidth) {1296 text = append(text[:maxe], ellipsis...)1297 rightTrim = true1298 }1299 // ..ri..1300 var diff int321293 text, diff = t.trimLeft(text, maxWidth-2)1301 text, diff = t.trimLeft(text, maxWidth-ellipsisWidth)13021303 // Transform offsets1296 transformOffsets(diff)1297 text = append([]rune(ellipsis), text...)1304 transformOffsets(diff, rightTrim)1305 text = append(ellipsis, text...)1306 }1307 } else {1300 text, _ = t.trimRight(text, maxWidth-2)1301 text = append(text, []rune(ellipsis)...)1308 text, _ = t.trimRight(text, maxWidth-ellipsisWidth)1309 text = append(text, ellipsis...)13101311 for idx, offset := range offsets {1304 offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-2))1312 offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-len(ellipsis)))1313 offsets[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))1314 }1315 }1316 displayWidth = t.displayWidthWithLimit(text, 0, displayWidth)
1582 unmodified lines
modified:test/test_go.rb+6 added
2206 unmodified lines
2207 tmux.until { |lines| refute_includes lines[0], 'hello' }2208 tmux.send_keys 'a'2209 end2210 end22112212 def test_ellipsis2213 tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter2214 tmux.until { |lines| assert_equal 1, lines.match_count }2215 tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }2216 end2217end22182219module TestShell2220 def setup
478 unmodified lines
modified:CHANGELOG.md+13 added
1CHANGELOG2=========340.30.05------6- Added `--ellipsis` option. You can take advantage of it to make fzf7 effectively search non-visible parts of the item.8 ```sh9 # Search against hidden line numbers on the far right10 nl /usr/share/dict/words |11 awk '{printf "%s%1000s\n", $2, $1}' |12 fzf --nth=-1 --no-hscroll --ellipsis='' |13 awk '{print $2}'14 ```15- Increased TTY buffer limit (#2748)16170.29.018------19- Added `change-preview(...)` action to change the `--preview` command20 - cf. `preview(...)` is a one-off action that doesn't change the default
1199 unmodified lines