From b819388acc4faa46e296f4e1f173b2cf2be8799f Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 26 Dec 2021 14:17:19 -0500 Subject: Hide cursor during redraws --- src/ui/terminal/line.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/ui/terminal/line.cc b/src/ui/terminal/line.cc index 0ae2d30..0848b22 100644 --- a/src/ui/terminal/line.cc +++ b/src/ui/terminal/line.cc @@ -39,6 +39,8 @@ namespace ec { namespace { +using ::goldfishterm::CursorVisibility; + constexpr absl::string_view kBeginningOfLine = "\r"; int CheckedCall(const char* what_arg, int r) { @@ -94,6 +96,7 @@ TerminalLine::~TerminalLine() noexcept { pthread_cancel(sigwinch_watcher_.native_handle()); sigwinch_watcher_.join(); + tty_->SetCursorVisibility(CursorVisibility::kNormal); ExitRawMode(); // Move the cursor to the start of the next line. @@ -107,6 +110,8 @@ void TerminalLine::SetLine(std::string text) { void TerminalLine::Refresh() { absl::MutexLock lock(&mu_); + tty_->SetCursorVisibility(CursorVisibility::kInvisible); + tty_->Flush(); tty_->BeginningOfLine(); if (line_.size() < columns_) { // We can fit the whole line and the cursor on the screen at once. @@ -117,6 +122,7 @@ void TerminalLine::Refresh() { tty_->Write(absl::string_view(&*line_.end() - to_display, to_display)); } tty_->ClearToEndOfLine(); + tty_->SetCursorVisibility(CursorVisibility::kNormal); tty_->Flush(); } @@ -145,11 +151,14 @@ void TerminalLine::Beep() { void TerminalLine::PrintLine(absl::string_view message) { { absl::MutexLock lock(&mu_); + tty_->SetCursorVisibility(CursorVisibility::kInvisible); + tty_->Flush(); tty_->BeginningOfLine(); tty_->CursorDown(); tty_->Write(message); tty_->BeginningOfLine(); tty_->CursorDown(); + tty_->SetCursorVisibility(CursorVisibility::kNormal); } Refresh(); // includes a flush } -- cgit v1.2.3