Skip to content
Myr

Add --preview-window option for cyclic scrolling

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

Close #2182

authored by Junegunn Choi · committed by Junegunn Choi · parent c0aa5a4 · Browse files · 3 files+16 added−7 removed
This commit

State

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

Diff stats

3 files+16 added−7 removed

  • other:+16 added−7 removed

3 files+16 added−7 removed

modified:src/options.go+8 added-3 removed
78 unmodified lines
7980 Preview81 --preview=COMMAND Command to preview highlighted line ({})82 --preview-window=OPT Preview window layout (default: right:50%)83 [up|down|left|right][:SIZE[%]][:wrap][:hidden][:+SCROLL[-OFFSET]]83 [up|down|left|right][:SIZE[%]][:wrap][:cycle][:hidden]84 [:+SCROLL[-OFFSET]]85 [:rounded|sharp|noborder]8687 Scripting88 -q, --query=STR Start the finder with the given query
74 unmodified lines
163 size sizeSpec164 scroll string165 hidden bool166 wrap bool167 cycle bool168 border tui.BorderShape169}170171// Options stores the values of command-line options
91 unmodified lines
263 Filter: nil,264 ToggleSort: false,265 Expect: make(map[int]string),266 Keymap: make(map[int][]action),265 Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, tui.BorderRounded},267 Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, false, tui.BorderRounded},268 PrintQuery: false,269 ReadZero: false,270 Printer: func(str string) { fmt.Println(str) },271 PrintSep: "\n",
726 unmodified lines
998 opts.position = posRight999 opts.size = sizeSpec{50, true}1000 opts.hidden = false1001 opts.wrap = false1002 opts.cycle = false10031004 tokens := strings.Split(input, ":")1005 sizeRegex := regexp.MustCompile("^[0-9]+%?$")1006 offsetRegex := regexp.MustCompile("^\\+([0-9]+|{-?[0-9]+})(-[0-9]+|-/[1-9][0-9]*)?$")
3 unmodified lines
1010 case "hidden":1011 opts.hidden = true1012 case "wrap":1013 opts.wrap = true1014 case "cycle":1015 opts.cycle = true1016 case "up", "top":1017 opts.position = posUp1018 case "down", "bottom":1019 opts.position = posDown
265 unmodified lines
1285 case "--no-preview":1286 opts.Preview.command = ""1287 case "--preview-window":1288 parsePreviewWindow(&opts.Preview,1284 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"))1289 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:rounded|sharp|noborder][:wrap][:cycle][:hidden][:+SCROLL[-OFFSET]]"))1290 case "--height":1291 opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))1292 case "--min-height":1293 opts.MinHeight = nextInt(allArgs, &i, "height required: HEIGHT")
206 unmodified lines
modified:src/terminal.go+7 added-4 removed
1882 unmodified lines
1883 scrollPreview := func(amount int) {1884 if !t.previewer.more {1885 return1886 }1887 newOffset := util.Constrain(1888 t.previewer.offset+amount, 0, t.previewer.lines-1)1887 newOffset := t.previewer.offset + amount1888 if t.preview.cycle {1889 newOffset = (newOffset + t.previewer.lines) % t.previewer.lines1890 }1891 newOffset = util.Constrain(newOffset, 0, t.previewer.lines-1)1892 if t.previewer.offset != newOffset {1893 t.previewer.offset = newOffset1894 req(reqPreviewRefresh)1895 }
63 unmodified lines
1959 scrollPreview(t.pwindow.Height())1960 }1961 case actPreviewHalfPageUp:1962 if t.hasPreviewWindow() {1960 scrollPreview(-t.pwindow.Height()/2)1963 scrollPreview(-t.pwindow.Height() / 2)1964 }1965 case actPreviewHalfPageDown:1966 if t.hasPreviewWindow() {1964 scrollPreview(t.pwindow.Height()/2)1967 scrollPreview(t.pwindow.Height() / 2)1968 }1969 case actBeginningOfLine:1970 t.cx = 01971 case actBackwardChar:
401 unmodified lines
modified:CHANGELOG.md+1 added
9 unmodified lines
10 --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \11 --preview-window +{2}-/212 ```13- Added `--preview-window` option for sharp edges (`--preview-window sharp`)14- Added `--preview-window` option for cyclic scrolling (`--preview-window cycle`)15- Reduced vertical padding around the preview window when `--preview-window16 noborder` is used17- Added actions for preview window18 - `preview-half-page-up`
917 unmodified lines