Skip to content
Myr

Add --hscroll-off=COL option

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

Close #513

authored by Junegunn Choi · committed by Junegunn Choi · parent cf8afc5 · Browse files · 5 files+43 added−5 removed
This commit

State

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

Diff stats

5 files+43 added−5 removed

  • tests:+12 added−0 removed
  • other:+31 added−5 removed

5 files+43 added−5 removed

modified:man/man1/fzf.1+6 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 "Feb 2016" "fzf 0.11.3" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Mar 2016" "fzf 0.11.4" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
145 unmodified lines
174.TP175.B "--no-hscroll"176Disable horizontal scroll177.TP178.BI "--hscroll-off=" "COL"179Number of screen columns to keep to the right of the highlighted substring180(default: 10). Setting it to a large value will cause the text to be positioned181on the center of the screen.182.TP183.B "--inline-info"184Display finder info inline with the query185.TP186.BI "--prompt=" "STR"
265 unmodified lines
modified:src/util/util.go+8 added
19 unmodified lines
20 }21 return max22}2324// Min returns the smallest integer25func Min(first int, second int) int {26 if first <= second {27 return first28 }29 return second30}3132// Min32 returns the smallest 32-bit integer33func Min32(first int32, second int32) int32 {34 if first <= second {35 return first
111 unmodified lines
modified:src/options.go+12 added
40 unmodified lines
41 --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)42 --tabstop=SPACES Number of spaces for a tab character (default: 8)43 --cycle Enable cyclic scroll44 --no-hscroll Disable horizontal scroll45 --hscroll-off=COL Number of screen columns to keep to the right of the46 highlighted substring (default: 10)47 --inline-info Display finder info inline with the query48 --prompt=STR Input prompt (default: '> ')49 --bind=KEYBINDS Custom key bindings. Refer to the man page.50 --history=FILE History file
58 unmodified lines
109 Black bool110 Reverse bool111 Cycle bool112 Hscroll bool113 HscrollOff int114 InlineInfo bool115 Prompt string116 Query string117 Select1 bool
39 unmodified lines
157 Black: false,158 Reverse: false,159 Cycle: false,160 Hscroll: true,161 HscrollOff: 10,162 InlineInfo: false,163 Prompt: "> ",164 Query: "",165 Select1: false,
632 unmodified lines
798 case "--hscroll":799 opts.Hscroll = true800 case "--no-hscroll":801 opts.Hscroll = false802 case "--hscroll-off":803 opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")804 case "--inline-info":805 opts.InlineInfo = true806 case "--no-inline-info":807 opts.InlineInfo = false
81 unmodified lines
889 } else if match, value := optString(arg, "--margin="); match {890 opts.Margin = parseMargin(value)891 } else if match, value := optString(arg, "--tabstop="); match {892 opts.Tabstop = atoi(value)893 } else if match, value := optString(arg, "--hscroll-off="); match {894 opts.HscrollOff = atoi(value)895 } else {896 errorExit("unknown option: " + arg)897 }898 }
2 unmodified lines
901 if opts.HeaderLines < 0 {902 errorExit("header lines must be a non-negative integer")903 }904905 if opts.HscrollOff < 0 {906 errorExit("hscroll offset must be a non-negative integer")907 }908909 if opts.Tabstop < 1 {910 errorExit("tab stop must be a positive integer")911 }912}
50 unmodified lines
modified:src/terminal.go+5 added-4 removed
24 unmodified lines
25 inlineInfo bool26 prompt string27 reverse bool28 hscroll bool29 hscrollOff int30 cx int31 cy int32 offset int33 yanked []rune
176 unmodified lines
210 inlineInfo: opts.InlineInfo,211 prompt: opts.Prompt,212 reverse: opts.Reverse,213 hscroll: opts.Hscroll,214 hscrollOff: opts.HscrollOff,215 cx: len(input),216 cy: 0,217 offset: 0,218 yanked: []rune{},
338 unmodified lines
557 return runes, trimmed558}559560func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {559 var maxe int32561 var maxe int562 for _, offset := range item.offsets {561 if offset[1] > maxe {562 maxe = offset[1]563 }563 maxe = util.Max(maxe, int(offset[1]))564 }565566 // Overflow567 text := make([]rune, len(item.text))568 copy(text, item.text)569 offsets := item.colorOffsets(col2, bold, current)570 maxWidth := C.MaxX() - 3 - t.marginInt[1] - t.marginInt[3]571 maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))572 fullWidth := displayWidth(text)573 if fullWidth > maxWidth {574 if t.hscroll {575 // Stri..
591 unmodified lines
modified:test/test_go.rb+12 added
1135 unmodified lines
1136 assert_equal %w[1 10 2 3 4 5 6 7 8 9],1137 `seq 10 | #{FZF} -f '1 | !1'`.lines.map(&:chomp)1138 end11391140 def test_hscroll_off1141 writelines tempname, ['=' * 10000 + '0123456789']1142 [0, 3, 6].each do |off|1143 tmux.prepare1144 tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 < #{tempname}", :Enter1145 tmux.until { |lines| lines[-3].end_with?((0..off).to_a.join + '..') }1146 tmux.send_keys '9'1147 tmux.until { |lines| lines[-3].end_with? '789' }1148 tmux.send_keys :Enter1149 end1150 end11511152private1153 def writelines path, lines1154 File.unlink path while File.exists? path1155 File.open(path, 'w') { |f| f << lines.join($/) + $/ }
304 unmodified lines