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 /goldfishterm | |
parent | 4e2e8f87f9ee7d22d1d1dfcf581694cc9d912afc (diff) |
Hide cursor during redraws
Diffstat (limited to 'goldfishterm')
-rw-r--r-- | goldfishterm/simple.cc | 18 | ||||
-rw-r--r-- | goldfishterm/simple.h | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/goldfishterm/simple.cc b/goldfishterm/simple.cc index 9c4c9a9..88ceef0 100644 --- a/goldfishterm/simple.cc +++ b/goldfishterm/simple.cc @@ -23,6 +23,7 @@ #include "goldfishterm/internal/emit.h" #include "goldfishterm/terminfo.h" +#include "third_party/abseil/absl/strings/str_cat.h" #include "third_party/abseil/absl/strings/string_view.h" namespace goldfishterm { @@ -48,6 +49,19 @@ absl::string_view TerminalNameFromEnvironment() { return name; } +StringCapability CursorVisibilityCapability(CursorVisibility v) { + switch (v) { + case CursorVisibility::kInvisible: + return StringCapability::kCursorInvisible; + case CursorVisibility::kNormal: + return StringCapability::kCursorNormal; + case CursorVisibility::kVeryVisible: + return StringCapability::kCursorVisible; + default: + throw std::invalid_argument(absl::StrCat("invalid CursorVisibility ", v)); + } +} + } // namespace SimpleTerminalOutput::SimpleTerminalOutput() @@ -59,6 +73,10 @@ SimpleTerminalOutput::SimpleTerminalOutput(const termios& tty) baud_ = cfgetospeed(&tty); } +void SimpleTerminalOutput::SetCursorVisibility(CursorVisibility v) { + return Emit(CursorVisibilityCapability(v)); +} + void SimpleTerminalOutput::Emit( StringCapability cap, std::vector<goldfishterm_internal::StringCapabilityParameter> parameters) { diff --git a/goldfishterm/simple.h b/goldfishterm/simple.h index 3f5cc9f..48a7789 100644 --- a/goldfishterm/simple.h +++ b/goldfishterm/simple.h @@ -26,6 +26,13 @@ namespace goldfishterm { +// The type of cursor in use. +enum class CursorVisibility { + kInvisible, + kNormal, + kVeryVisible, +}; + // Looks up escape sequences for the terminal described in the TERM environment // variable, and allows sending those escape sequences to standard output. // @@ -58,6 +65,9 @@ class SimpleTerminalOutput final { // Moves the cursor down one line. void CursorDown() { Emit(StringCapability::kCursorDown); } + // Sets the cursor visibility. + void SetCursorVisibility(CursorVisibility); + private: void Emit(StringCapability, std::vector<goldfishterm_internal::StringCapabilityParameter> = {}); |