| 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. |