Skip to content

Commit a85480e

Browse files
committed
Add --no-clear-on-start option
This can be used in shell integration, to avoid clear the cmdline content
1 parent b29e2ee commit a85480e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ type Options struct {
650650
ListenAddr *listenAddress
651651
Unsafe bool
652652
ClearOnExit bool
653+
KeepScreen bool
653654
WalkerOpts walkerOpts
654655
WalkerRoot []string
655656
WalkerSkip []string
@@ -3277,6 +3278,8 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
32773278
opts.ClearOnExit = true
32783279
case "--no-clear":
32793280
opts.ClearOnExit = false
3281+
case "--no-clear-on-start":
3282+
opts.KeepScreen = true
32803283
case "--walker":
32813284
str, err := nextString("walker options required [file][,dir][,follow][,hidden]")
32823285
if err != nil {

src/terminal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
942942
if tui.HasFullscreenRenderer() {
943943
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
944944
} else {
945-
renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit,
945+
renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, opts.KeepScreen,
946946
true, func(h int) int { return h })
947947
}
948948
} else {
@@ -958,7 +958,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
958958
effectiveMinHeight += borderLines(opts.BorderShape)
959959
return min(termHeight, max(evaluateHeight(opts, termHeight), effectiveMinHeight))
960960
}
961-
renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc)
961+
renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, opts.KeepScreen, false, maxHeightFunc)
962962
}
963963
if err != nil {
964964
return nil, err

src/tui/light.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type LightRenderer struct {
100100
mouse bool
101101
forceBlack bool
102102
clearOnExit bool
103+
keepScreen bool
103104
prevDownTime time.Time
104105
clicks [][2]int
105106
ttyin *os.File
@@ -146,7 +147,7 @@ type LightWindow struct {
146147
wrapSignWidth int
147148
}
148149

149-
func NewLightRenderer(ttyDefault string, ttyin *os.File, theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, clearOnExit bool, fullscreen bool, maxHeightFunc func(int) int) (Renderer, error) {
150+
func NewLightRenderer(ttyDefault string, ttyin *os.File, theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, clearOnExit bool, keepScreen bool, fullscreen bool, maxHeightFunc func(int) int) (Renderer, error) {
150151
out, err := openTtyOut(ttyDefault)
151152
if err != nil {
152153
out = os.Stderr
@@ -156,6 +157,7 @@ func NewLightRenderer(ttyDefault string, ttyin *os.File, theme *ColorTheme, forc
156157
forceBlack: forceBlack,
157158
mouse: mouse,
158159
clearOnExit: clearOnExit,
160+
keepScreen: keepScreen,
159161
ttyin: ttyin,
160162
ttyout: out,
161163
yoffset: 0,
@@ -195,7 +197,7 @@ func (r *LightRenderer) Init() error {
195197
} else {
196198
// We assume that --no-clear is used for repetitive relaunching of fzf.
197199
// So we do not clear the lower bottom of the screen.
198-
if r.clearOnExit {
200+
if r.clearOnExit && r.keepScreen {
199201
r.csi("J")
200202
}
201203
y, x := r.findOffset()

0 commit comments

Comments
 (0)