From 53348feb8959754497453232ffacd4bd3f1154ea Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 4 Mar 2017 11:29:31 +0900 Subject: Add --no-clear option --- src/options.go | 6 ++++++ src/terminal.go | 4 ++-- src/tui/light.go | 24 ++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/options.go b/src/options.go index c78d2bfe..7a3d60cb 100644 --- a/src/options.go +++ b/src/options.go @@ -186,6 +186,7 @@ type Options struct { Margin [4]sizeSpec Bordered bool Tabstop int + ClearOnExit bool Version bool } @@ -234,6 +235,7 @@ func defaultOptions() *Options { HeaderLines: 0, Margin: defaultMargin(), Tabstop: 8, + ClearOnExit: true, Version: false} } @@ -1099,6 +1101,10 @@ func parseOptions(opts *Options, allArgs []string) { nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)")) case "--tabstop": opts.Tabstop = nextInt(allArgs, &i, "tab stop required") + case "--clear": + opts.ClearOnExit = true + case "--no-clear": + opts.ClearOnExit = false case "--version": opts.Version = true default: diff --git a/src/terminal.go b/src/terminal.go index f556badd..3a83bad2 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -316,11 +316,11 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { } return util.Min(termHeight, util.Max(maxHeight, effectiveMinHeight)) } - renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, maxHeightFunc) + renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, maxHeightFunc) } else if tui.HasFullscreenRenderer() { renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse) } else { - renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, + renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, func(h int) int { return h }) } wordRubout := "[^[:alnum:]][[:alnum:]]" diff --git a/src/tui/light.go b/src/tui/light.go index fb8f4f03..2af31c4b 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -74,6 +74,7 @@ type LightRenderer struct { theme *ColorTheme mouse bool forceBlack bool + clearOnExit bool prevDownTime time.Time clickY []int ttyin *os.File @@ -106,11 +107,12 @@ type LightWindow struct { bg Color } -func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, maxHeightFunc func(int) int) Renderer { +func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, clearOnExit bool, maxHeightFunc func(int) int) Renderer { r := LightRenderer{ theme: theme, forceBlack: forceBlack, mouse: mouse, + clearOnExit: clearOnExit, ttyin: openTtyIn(), yoffset: 0, tabstop: tabstop, @@ -571,14 +573,20 @@ func (r *LightRenderer) Refresh() { func (r *LightRenderer) Close() { // r.csi("u") - if r.fullscreen { - r.rmcup() - } else { - r.origin() - if r.upOneLine { - r.csi("A") + if r.clearOnExit { + if r.fullscreen { + r.rmcup() + } else { + r.origin() + if r.upOneLine { + r.csi("A") + } + r.csi("J") } - r.csi("J") + } else if r.fullscreen { + r.csi("G") + } else { + r.move(r.height, 0) } if r.mouse { r.csi("?1000l") -- cgit v1.2.3