Fix when cursor is shown by edit:clear

Showing the cursor should only happen after the prompt is redrawn.

Fixes #1238
This commit is contained in:
Kurtis Rader 2021-02-25 19:39:27 -08:00 committed by Qi Xiao
parent 6439a3cbb2
commit 663e04ff75
4 changed files with 30 additions and 2 deletions

View File

@ -126,6 +126,12 @@ func (t *fakeTTY) UpdateBuffer(bufNotes, buf *term.Buffer, _ bool) error {
return nil
}
func (t *fakeTTY) HideCursor() {
}
func (t *fakeTTY) ShowCursor() {
}
func (t *fakeTTY) ClearScreen() {
t.cleared++
}

View File

@ -19,6 +19,9 @@ type Writer interface {
// ClearScreen clears the terminal screen and places the cursor at the top
// left corner.
ClearScreen()
// Control whether the terminal cursor is visible.
HideCursor()
ShowCursor()
}
// writer renders the editor UI.
@ -186,11 +189,17 @@ func (w *writer) CommitBuffer(bufNoti, buf *Buffer, fullRefresh bool) error {
return nil
}
func (w *writer) HideCursor() {
fmt.Fprint(w.file, hideCursor)
}
func (w *writer) ShowCursor() {
fmt.Fprint(w.file, showCursor)
}
func (w *writer) ClearScreen() {
fmt.Fprint(w.file,
hideCursor,
"\033[H", // move cursor to the top left corner
"\033[2J", // clear entire buffer
showCursor,
)
}

View File

@ -55,6 +55,9 @@ type TTY interface {
// ClearScreen clears the terminal screen and places the cursor at the top
// left corner.
ClearScreen()
// Control whether the terminal cursor is visible.
HideCursor()
ShowCursor()
}
type aTTY struct {
@ -131,6 +134,14 @@ func (t *aTTY) UpdateBuffer(bufNotes, bufMain *term.Buffer, full bool) error {
return t.w.CommitBuffer(bufNotes, bufMain, full)
}
func (t *aTTY) HideCursor() {
t.w.HideCursor()
}
func (t *aTTY) ShowCursor() {
t.w.ShowCursor()
}
func (t *aTTY) ClearScreen() {
t.w.ClearScreen()
}

View File

@ -91,8 +91,10 @@ func redraw(app cli.App, opts redrawOpts) {
// the screen.
func clear(app cli.App, tty cli.TTY) {
tty.HideCursor()
tty.ClearScreen()
app.RedrawFull()
tty.ShowCursor()
}
//elvdoc:fn insert-raw