xaizek / libcursedrl (License: GPLv3+) (since 2019-03-24)
libcursed extension for integration with readline.
Commit 6b93b309df1fd2f3c3e9cad98425139e0a78b6e6

Display cursor only inside PromptRequest::prompt()
Otherwise, it can stay visible when it shouldn't because PromptRequest
just wasn't destructed yet.
Author: xaizek
Author date (UTC): 2022-06-24 21:44
Committer name: xaizek
Committer date (UTC): 2022-06-24 21:44
Parent(s): 80dd8d5688964d2b6ff21087a18182320e9e74f9
Signing key: 99DC5E4DB05F6BE2
Tree: 072e4fd6e59c3418cd9d9bd72813aab350137fee
File Lines added Lines deleted
PromptRequest.cpp 25 7
PromptRequest.hpp 1 3
File PromptRequest.cpp changed (mode: 100644) (index a6be77d..aaf8c27)
... ... private:
69 69 struct sigaction sa; // Saved signal handling information. struct sigaction sa; // Saved signal handling information.
70 70 }; };
71 71
72 // Hides cursor when an object of this type leaves scope.
73 class AutoHideCursor
74 {
75 public:
76 // Remembers argument.
77 explicit AutoHideCursor(cursed::Screen &screen) : screen(screen)
78 { }
79
80 // Hides cursor.
81 ~AutoHideCursor() try {
82 screen.hideCursor();
83 } catch (...) { }
84
85 AutoHideCursor(const AutoHideCursor &rhs) = delete;
86 AutoHideCursor(AutoHideCursor &&rhs) = delete;
87 AutoHideCursor & operator=(const AutoHideCursor &rhs) = delete;
88 AutoHideCursor & operator=(AutoHideCursor &&rhs) = delete;
89
90 private:
91 cursed::Screen &screen; // Screen on which to operate.
92 };
93
72 94 } }
73 95
74 96 void void
 
... ... PromptResult::PromptResult(std::wstring input, bool accepted)
90 112 PromptRequest::PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea) PromptRequest::PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea)
91 113 : input(cursed::Keypad::Disabled), screen(screen), promptArea(promptArea) : input(cursed::Keypad::Disabled), screen(screen), promptArea(promptArea)
92 114 { {
93 screen.showCursor(&promptArea);
94
95 115 promptHi.setBold(true); promptHi.setBold(true);
96 116 } }
97 117
98 PromptRequest::~PromptRequest()
99 {
100 screen.hideCursor();
101 }
102
103 118 void void
104 119 PromptRequest::setOnInputChanged(inputChangedFunc newOnInputChanged) PromptRequest::setOnInputChanged(inputChangedFunc newOnInputChanged)
105 120 { {
 
... ... PromptResult
116 131 PromptRequest::prompt(const std::wstring &invitation, PromptRequest::prompt(const std::wstring &invitation,
117 132 const std::wstring &initial) const std::wstring &initial)
118 133 { {
134 screen.showCursor(&promptArea);
135 AutoHideCursor autoHideCursor(screen);
136
119 137 initialValue = cursed::toNarrow(initial); initialValue = cursed::toNarrow(initial);
120 138 lastValue = initialValue; lastValue = initialValue;
121 139
File PromptRequest.hpp changed (mode: 100644) (index 5af0750..c15eb62)
... ... class PromptRequest
71 71 > completerFunc; > completerFunc;
72 72
73 73 public: public:
74 // Remembers arguments and makes cursor visible.
74 // Remembers arguments.
75 75 PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea); PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea);
76 // Cleans up and hides cursor.
77 ~PromptRequest();
78 76
79 77 PromptRequest(const PromptRequest &rhs) = delete; PromptRequest(const PromptRequest &rhs) = delete;
80 78 PromptRequest(PromptRequest &&rhs) = delete; PromptRequest(PromptRequest &&rhs) = delete;
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/libcursedrl

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/libcursedrl

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master