Skip to content

Commit

Permalink
[display] Hide the cursor in interactive mode.
Browse files Browse the repository at this point in the history
Hiding the cursor should eliminate the last of the redraw artifacts.
  • Loading branch information
pgavlin committed Dec 20, 2022
1 parent 77b22d1 commit f92cb3d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/backend/display/internal/terminal/info.go
Expand Up @@ -14,6 +14,8 @@ type Info interface {
ClearLine(out io.Writer)
CursorUp(out io.Writer, count int)
CursorDown(out io.Writer, count int)
HideCursor(out io.Writer)
ShowCursor(out io.Writer)
}

/* Satisfied by gotty.TermInfo as well as noTermInfo from below */
Expand Down Expand Up @@ -87,3 +89,15 @@ func (i info) CursorDown(out io.Writer, count int) {
fmt.Fprintf(out, "\x1b[%dB", count)
}
}

func (i info) HideCursor(out io.Writer) {
if attr, err := i.Parse("civis"); err == nil {
fmt.Fprintf(out, "%s", attr)
}
}

func (i info) ShowCursor(out io.Writer) {
if attr, err := i.Parse("cnorm"); err == nil {
fmt.Fprintf(out, "%s", attr)
}
}
8 changes: 8 additions & 0 deletions pkg/backend/display/internal/terminal/mock.go
Expand Up @@ -64,6 +64,14 @@ func (t *MockTerminal) CursorDown(count int) {
t.info.CursorDown(t, count)
}

func (t *MockTerminal) HideCursor() {
t.info.HideCursor(t)
}

func (t *MockTerminal) ShowCursor() {
t.info.ShowCursor(t)
}

func (t *MockTerminal) ReadKey() (string, error) {
k, ok := <-t.keys
if !ok {
Expand Down
10 changes: 10 additions & 0 deletions pkg/backend/display/internal/terminal/term.go
Expand Up @@ -21,6 +21,8 @@ type Terminal interface {
ClearEnd()
CursorUp(count int)
CursorDown(count int)
HideCursor()
ShowCursor()

ReadKey() (string, error)
}
Expand Down Expand Up @@ -144,6 +146,14 @@ func (t *terminal) CursorDown(count int) {
t.info.CursorDown(t.out, count)
}

func (t *terminal) HideCursor() {
t.info.HideCursor(t.out)
}

func (t *terminal) ShowCursor() {
t.info.ShowCursor(t.out)
}

func (t *terminal) ReadKey() (string, error) {
if t.in == nil {
return "", io.EOF
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/display/tree.go
Expand Up @@ -58,6 +58,7 @@ func newInteractiveRenderer(term terminal.Terminal, opts Options) progressRender
if !term.IsRaw() {
return newInteractiveMessageRenderer(term, opts)
}
term.HideCursor()

r := &treeRenderer{
opts: opts,
Expand All @@ -75,6 +76,7 @@ func newInteractiveRenderer(term terminal.Terminal, opts Options) progressRender
}

func (r *treeRenderer) Close() error {
r.term.ShowCursor()
return r.term.Close()
}

Expand Down

0 comments on commit f92cb3d

Please sign in to comment.