diff options
author | Benjamin Barenblat <bbarenblat@gmail.com> | 2021-12-26 14:17:19 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbarenblat@gmail.com> | 2021-12-26 14:55:35 -0500 |
commit | b819388acc4faa46e296f4e1f173b2cf2be8799f (patch) | |
tree | 5d70c7c64f978055ec4e0ecba38bf7cd85af5a7f /src | |
parent | 4e2e8f87f9ee7d22d1d1dfcf581694cc9d912afc (diff) |
Hide cursor during redraws
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/terminal/line.cc | 9 |
1 files changed, 9 insertions, 0 deletions
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 } |