Add --no-hscroll option to disable horizontal scroll
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #193
authored by Junegunn Choi · committed by Junegunn Choi · parent 3e1e75f · Browse files · 4 files·+50 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+50 added−20 removed
- other:+50 added−20 removed
Provenance
- Commit
48ab872- Tree
8475c93- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
3e1e75f
4 files changed+50 added−20 removed
modified:man/man1/fzf.1+3 added
87 unmodified lines88 .TP89 .B "--reverse"90 Reverse orientation91 .TP92+.B "--no-hscroll"93+Disable horizontal scroll94+.TP95 .BI "--prompt=" "STR"96 Input prompt (default: '> ')97 .SS Scripting98 .TP108 unmodified linesmodified:src/util/util.go+8 added
17 unmodified lines18 }19 return max20 }21 22+// Max32 returns the smallest 32-bit integer23+func Min32(first int32, second int32) int32 {24+ if first <= second {25+ return first26+ }27+ return second28+}29+30 // Max32 returns the largest 32-bit integer31 func Max32(first int32, second int32) int32 {32 if first > second {33 return first46 unmodified linesmodified:src/options.go+7 added
36 unmodified lines37 +c, --no-color Disable colors38 +2, --no-256 Disable 256-color39 --black Use black background40 --reverse Reverse orientation41+ --no-hscroll Disable horizontal scroll42 --prompt=STR Input prompt (default: '> ')43 44 Scripting45 -q, --query=STR Start the finder with the given query47 unmodified lines93 Color bool94 Color256 bool95 Black bool96 Reverse bool97+ Hscroll bool98 Prompt string99 Query string100 Select1 bool101 Exit0 bool20 unmodified lines122 Color: true,123 Color256: strings.Contains(os.Getenv("TERM"), "256"),124 Black: false,125 Reverse: false,126+ Hscroll: true,127 Prompt: "> ",128 Query: "",129 Select1: false,130 Exit0: false,175 unmodified lines306 case "--reverse":307 opts.Reverse = true308 case "--no-reverse":309 opts.Reverse = false310+ case "--hscroll":311+ opts.Hscroll = true312+ case "--no-hscroll":313+ opts.Hscroll = false314 case "-1", "--select-1":315 opts.Select1 = true316 case "+1", "--no-select-1":317 opts.Select1 = false67 unmodified linesmodified:src/terminal.go+32 added-20 removed
20 unmodified lines21 // Terminal represents terminal input/output22 type Terminal struct {23 prompt string24 reverse bool25+ hscroll bool26 cx int27 cy int28 offset int29 yanked []rune58 unmodified lines88 input := []rune(opts.Query)89 return &Terminal{90 prompt: opts.Prompt,91 reverse: opts.Reverse,92+ hscroll: opts.Hscroll,93 cx: len(input),94 cy: 0,95 offset: 0,96 yanked: []rune{},222 unmodified lines319 }320 return runes, trimmed321 }322 321-func (*Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {323+func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {324 var maxe int32325 for _, offset := range item.offsets {326 if offset[1] > maxe {327 maxe = offset[1]5 unmodified lines333 offsets := item.colorOffsets(col2, bold, current)334 maxWidth := C.MaxX() - 3335 fullWidth := displayWidth(text)336 if fullWidth > maxWidth {335- // Stri..336- matchEndWidth := displayWidth(text[:maxe])337- if matchEndWidth <= maxWidth-2 {338- text, _ = trimRight(text, maxWidth-2)339- text = append(text, []rune("..")...)340- } else {337+ if t.hscroll {338 // Stri..339+ matchEndWidth := displayWidth(text[:maxe])340+ if matchEndWidth <= maxWidth-2 {341+ text, _ = trimRight(text, maxWidth-2)342+ text = append(text, []rune("..")...)343+ } else {344+ // Stri..342- if matchEndWidth < fullWidth-2 {343- text = append(text[:maxe], []rune("..")...)345+ if matchEndWidth < fullWidth-2 {346+ text = append(text[:maxe], []rune("..")...)347+ }348+ // ..ri..349+ var diff int32350+ text, diff = trimLeft(text, maxWidth-2)351+352+ // Transform offsets353+ for idx, offset := range offsets {354+ b, e := offset.offset[0], offset.offset[1]355+ b += 2 - diff356+ e += 2 - diff357+ b = util.Max32(b, 2)358+ offsets[idx].offset[0] = b359+ offsets[idx].offset[1] = util.Max32(b, e)360+ }361+ text = append([]rune(".."), text...)362 }345- // ..ri..346- var diff int32347- text, diff = trimLeft(text, maxWidth-2)363+ } else {364+ text, _ = trimRight(text, maxWidth-2)365+ text = append(text, []rune("..")...)366 349- // Transform offsets367 for idx, offset := range offsets {351- b, e := offset.offset[0], offset.offset[1]352- b += 2 - diff353- e += 2 - diff354- b = util.Max32(b, 2)355- offsets[idx].offset[0] = b356- offsets[idx].offset[1] = util.Max32(b, e)368+ offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-2))369+ offsets[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))370 }358- text = append([]rune(".."), text...)371 }372 }373 374 var index int32387 unmodified lines