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

Always return user input, even on cancellation
Author: xaizek
Author date (UTC): 2022-06-23 18:25
Committer name: xaizek
Committer date (UTC): 2022-06-23 18:25
Parent(s): e3a629e92b63d83f2719e11e364c1b25b7be7313
Signing key: 99DC5E4DB05F6BE2
Tree: 673a52965b50bedf4f9efb8496053ecbc4b89dd9
File Lines added Lines deleted
PromptRequest.cpp 4 6
PromptRequest.hpp 9 10
README.md 1 1
File PromptRequest.cpp changed (mode: 100644) (index 04a5479..a6be77d)
... ... PromptRequest::saveHistory(const std::string &path)
83 83 static_cast<void>(write_history(path.c_str())); static_cast<void>(write_history(path.c_str()));
84 84 } }
85 85
86 PromptResult::PromptResult() : hasInput(false)
87 { }
88
89 PromptResult::PromptResult(std::wstring result)
90 : result(std::move(result)), hasInput(true)
86 PromptResult::PromptResult(std::wstring input, bool accepted)
87 : input(std::move(input)), accepted(accepted)
91 88 { } { }
92 89
93 90 PromptRequest::PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea) PromptRequest::PromptRequest(cursed::Screen &screen, cursed::Prompt &promptArea)
 
... ... PromptRequest::prompt(const std::wstring &invitation,
171 168 add_history(line.get()); add_history(line.get());
172 169 } }
173 170
174 return (cancelled ? PromptResult() : cursed::toWide(line.get()));
171 std::wstring input = (line == nullptr ? L"" : cursed::toWide(line.get()));
172 return PromptResult(input, !cancelled);
175 173 } }
176 174
177 175 void void
File PromptRequest.hpp changed (mode: 100644) (index b1a29ec..5af0750)
... ... class PromptResult
41 41 friend class PromptRequest; friend class PromptRequest;
42 42
43 43 private: private:
44 // No input was provided (request was declined/cancelled).
45 PromptResult();
46 // An input was provided.
47 PromptResult(std::wstring result);
44 // An input was provided. `false` in `accepted` parameter means request
45 // was declined/cancelled.
46 PromptResult(std::wstring input, bool accepted);
48 47
49 48 public: public:
50 // Retrieves input.
49 // Retrieves input regardless of whether it was accepted.
51 50 std::wstring getResult() const std::wstring getResult() const
52 { return result; }
51 { return input; }
53 52
54 // Checks if result contains input.
53 // Checks if input was accepted.
55 54 operator bool() const operator bool() const
56 { return hasInput; }
55 { return accepted; }
57 56
58 57 private: private:
59 std::wstring result; // Input.
60 bool hasInput; // Whether input makes sense.
58 std::wstring input; // Input.
59 bool accepted; // Whether input was accepted.
61 60 }; };
62 61
63 62 // Provides text editing facility via prompt. // Provides text editing facility via prompt.
File README.md changed (mode: 100644) (index 606ae71..22af121)
1 **libcursedrl**, _2019_
1 **libcursedrl**, _2019 -- 2022_
2 2
3 3 _This file last updated on 1 January, 2022_ _This file last updated on 1 January, 2022_
4 4
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