mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-13 03:05:49 -07:00
Adjust --no-clear option for repetitive relaunching
Related: https://gist.github.com/junegunn/4963bab6ace453f7f529d2d0e01b1d85 Close #974
This commit is contained in:
@@ -87,6 +87,7 @@ type Terminal struct {
|
|||||||
margin [4]sizeSpec
|
margin [4]sizeSpec
|
||||||
strong tui.Attr
|
strong tui.Attr
|
||||||
bordered bool
|
bordered bool
|
||||||
|
cleanExit bool
|
||||||
border tui.Window
|
border tui.Window
|
||||||
window tui.Window
|
window tui.Window
|
||||||
pborder tui.Window
|
pborder tui.Window
|
||||||
@@ -366,6 +367,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
history: opts.History,
|
history: opts.History,
|
||||||
margin: opts.Margin,
|
margin: opts.Margin,
|
||||||
bordered: opts.Bordered,
|
bordered: opts.Bordered,
|
||||||
|
cleanExit: opts.ClearOnExit,
|
||||||
strong: strongAttr,
|
strong: strongAttr,
|
||||||
cycle: opts.Cycle,
|
cycle: opts.Cycle,
|
||||||
header: header,
|
header: header,
|
||||||
@@ -1341,7 +1343,14 @@ func (t *Terminal) Loop() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
exit := func(code int) {
|
exit := func(code int, printQuery bool) {
|
||||||
|
if !t.cleanExit && t.fullscreen && t.inlineInfo {
|
||||||
|
t.placeCursor()
|
||||||
|
}
|
||||||
|
t.tui.Close()
|
||||||
|
if printQuery {
|
||||||
|
t.printer(string(t.input))
|
||||||
|
}
|
||||||
if code <= exitNoMatch && t.history != nil {
|
if code <= exitNoMatch && t.history != nil {
|
||||||
t.history.append(string(t.input))
|
t.history.append(string(t.input))
|
||||||
}
|
}
|
||||||
@@ -1389,11 +1398,11 @@ func (t *Terminal) Loop() {
|
|||||||
case reqRedraw:
|
case reqRedraw:
|
||||||
t.redraw()
|
t.redraw()
|
||||||
case reqClose:
|
case reqClose:
|
||||||
t.tui.Close()
|
|
||||||
if t.output() {
|
if t.output() {
|
||||||
exit(exitOk)
|
exit(exitOk, false)
|
||||||
|
} else {
|
||||||
|
exit(exitNoMatch, false)
|
||||||
}
|
}
|
||||||
exit(exitNoMatch)
|
|
||||||
case reqPreviewDisplay:
|
case reqPreviewDisplay:
|
||||||
t.previewer.text = value.(string)
|
t.previewer.text = value.(string)
|
||||||
t.previewer.lines = strings.Count(t.previewer.text, "\n")
|
t.previewer.lines = strings.Count(t.previewer.text, "\n")
|
||||||
@@ -1402,12 +1411,9 @@ func (t *Terminal) Loop() {
|
|||||||
case reqPreviewRefresh:
|
case reqPreviewRefresh:
|
||||||
t.printPreview()
|
t.printPreview()
|
||||||
case reqPrintQuery:
|
case reqPrintQuery:
|
||||||
t.tui.Close()
|
exit(exitOk, true)
|
||||||
t.printer(string(t.input))
|
|
||||||
exit(exitOk)
|
|
||||||
case reqQuit:
|
case reqQuit:
|
||||||
t.tui.Close()
|
exit(exitInterrupt, false)
|
||||||
exit(exitInterrupt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.placeCursor()
|
t.placeCursor()
|
||||||
|
@@ -182,10 +182,18 @@ func (r *LightRenderer) Init() {
|
|||||||
if r.fullscreen {
|
if r.fullscreen {
|
||||||
r.smcup()
|
r.smcup()
|
||||||
} else {
|
} else {
|
||||||
r.csi("J")
|
// We assume that --no-clear is used for repetitive relaunching of fzf.
|
||||||
|
// So we do not clear the lower bottom of the screen.
|
||||||
|
if r.clearOnExit {
|
||||||
|
r.csi("J")
|
||||||
|
}
|
||||||
y, x := r.findOffset()
|
y, x := r.findOffset()
|
||||||
r.mouse = r.mouse && y >= 0
|
r.mouse = r.mouse && y >= 0
|
||||||
if x > 0 {
|
// When --no-clear is used for repetitive relaunching, there is a small
|
||||||
|
// time frame between fzf processes where the user keystrokes are not
|
||||||
|
// captured by either of fzf process which can cause x offset to be
|
||||||
|
// increased and we're left with unwanted extra new line.
|
||||||
|
if x > 0 && r.clearOnExit {
|
||||||
r.upOneLine = true
|
r.upOneLine = true
|
||||||
r.makeSpace()
|
r.makeSpace()
|
||||||
}
|
}
|
||||||
@@ -200,7 +208,7 @@ func (r *LightRenderer) Init() {
|
|||||||
r.csi(fmt.Sprintf("%dA", r.MaxY()-1))
|
r.csi(fmt.Sprintf("%dA", r.MaxY()-1))
|
||||||
r.csi("G")
|
r.csi("G")
|
||||||
r.csi("K")
|
r.csi("K")
|
||||||
// r.csi("s")
|
r.csi("s")
|
||||||
if !r.fullscreen && r.mouse {
|
if !r.fullscreen && r.mouse {
|
||||||
r.yoffset, _ = r.findOffset()
|
r.yoffset, _ = r.findOffset()
|
||||||
}
|
}
|
||||||
@@ -586,10 +594,8 @@ func (r *LightRenderer) Close() {
|
|||||||
}
|
}
|
||||||
r.csi("J")
|
r.csi("J")
|
||||||
}
|
}
|
||||||
} else if r.fullscreen {
|
} else if !r.fullscreen {
|
||||||
r.csi("G")
|
r.csi("u")
|
||||||
} else {
|
|
||||||
r.move(r.height, 0)
|
|
||||||
}
|
}
|
||||||
if r.mouse {
|
if r.mouse {
|
||||||
r.csi("?1000l")
|
r.csi("?1000l")
|
||||||
|
@@ -1253,11 +1253,12 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_no_clear
|
def test_no_clear
|
||||||
tmux.send_keys 'seq 100 | fzf --no-clear --inline-info --height 5', :Enter
|
tmux.send_keys "seq 10 | fzf --no-clear --inline-info --height 5 > #{tempname}", :Enter
|
||||||
prompt = '> < 100/100'
|
prompt = '> < 10/10'
|
||||||
tmux.until { |lines| lines[-1] == prompt }
|
tmux.until { |lines| lines[-1] == prompt }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
tmux.until { |lines| lines[-2] == prompt && lines[-1] == '1' }
|
tmux.until { |_| %w[1] == File.readlines(tempname).map(&:chomp) }
|
||||||
|
tmux.until { |lines| lines[-1] == prompt }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_change_top
|
def test_change_top
|
||||||
|
Reference in New Issue
Block a user