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
Provenance
- Commit
2ccdf21- Tree
260774a- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
cf8afc5
5 files changed+43 added−5 removed
modified:man/man1/fzf.1+6 added-1 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE 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"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 145 unmodified lines174 .TP175 .B "--no-hscroll"176 Disable horizontal scroll177 .TP178+.BI "--hscroll-off=" "COL"179+Number 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 positioned181+on the center of the screen.182+.TP183 .B "--inline-info"184 Display finder info inline with the query185 .TP186 .BI "--prompt=" "STR"265 unmodified linesmodified:src/util/util.go+8 added
19 unmodified lines20 }21 return max22 }23 24+// Min returns the smallest integer25+func Min(first int, second int) int {26+ if first <= second {27+ return first28+ }29+ return second30+}31+32 // Min32 returns the smallest 32-bit integer33 func Min32(first int32, second int32) int32 {34 if first <= second {35 return first111 unmodified linesmodified:src/options.go+12 added
40 unmodified lines41 --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 file58 unmodified lines109 Black bool110 Reverse bool111 Cycle bool112 Hscroll bool113+ HscrollOff int114 InlineInfo bool115 Prompt string116 Query string117 Select1 bool39 unmodified lines157 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 lines798 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 = false81 unmodified lines889 } 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 lines901 if opts.HeaderLines < 0 {902 errorExit("header lines must be a non-negative integer")903 }904 905+ if opts.HscrollOff < 0 {906+ errorExit("hscroll offset must be a non-negative integer")907+ }908+909 if opts.Tabstop < 1 {910 errorExit("tab stop must be a positive integer")911 }912 }50 unmodified linesmodified:src/terminal.go+5 added-4 removed
24 unmodified lines25 inlineInfo bool26 prompt string27 reverse bool28 hscroll bool29+ hscrollOff int30 cx int31 cy int32 offset int33 yanked []rune176 unmodified lines210 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 lines557 return runes, trimmed558 }559 560 func (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 }565 566 // 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 linesmodified:test/test_go.rb+12 added
1135 unmodified lines1136 assert_equal %w[1 10 2 3 4 5 6 7 8 9],1137 `seq 10 | #{FZF} -f '1 | !1'`.lines.map(&:chomp)1138 end1139 1140+ 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+ end1151+1152 private1153 def writelines path, lines1154 File.unlink path while File.exists? path1155 File.open(path, 'w') { |f| f << lines.join($/) + $/ }304 unmodified lines