From c79c4a988cde2621cf87a59265233ed7e9e0b63e Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 10 Mar 2021 16:59:00 +0000 Subject: [PATCH] restore cursor on error (#337) --- terminal/cursor.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/terminal/cursor.go b/terminal/cursor.go index c294ca4c..1bc427c9 100644 --- a/terminal/cursor.go +++ b/terminal/cursor.go @@ -167,8 +167,11 @@ func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) { // hide the cursor (so it doesn't blink when getting the size of the terminal) c.Hide() + defer c.Show() + // save the current location of the cursor c.Save() + defer c.Restore() // move the cursor to the very bottom of the terminal c.Move(999, 999) @@ -179,11 +182,6 @@ func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) { return nil, err } - // move back where we began - c.Restore() - - // show the cursor - c.Show() // since the bottom was calculated in the lower right corner, it // is the dimensions we are looking for return bottom, nil