| File src/PromptRequest.cpp changed (mode: 100644) (index 4758e2d..823cb9a) |
| ... |
... |
PromptResult::PromptResult(std::wstring result) |
| 77 |
77 |
{ } |
{ } |
| 78 |
78 |
|
|
| 79 |
79 |
PromptRequest::PromptRequest(cursed::Input &input, cursed::Screen &screen, |
PromptRequest::PromptRequest(cursed::Input &input, cursed::Screen &screen, |
| 80 |
|
cursed::Prompt &promptArea) |
|
| 81 |
|
: input(input), screen(screen), promptArea(promptArea) |
|
|
80 |
|
cursed::Prompt &promptArea, |
|
81 |
|
inputChangedFunc onInputChanged) |
|
82 |
|
: input(input), screen(screen), promptArea(promptArea), |
|
83 |
|
onInputChanged(std::move(onInputChanged)) |
| 82 |
84 |
{ |
{ |
| 83 |
85 |
screen.showCursor(); |
screen.showCursor(); |
| 84 |
86 |
} |
} |
| |
| ... |
... |
PromptRequest::prompt(const std::wstring &invitation, |
| 93 |
95 |
const std::wstring &initial) |
const std::wstring &initial) |
| 94 |
96 |
{ |
{ |
| 95 |
97 |
initialValue = toNarrow(initial); |
initialValue = toNarrow(initial); |
|
98 |
|
lastValue = initialValue; |
| 96 |
99 |
|
|
| 97 |
100 |
static PromptRequest *instance; |
static PromptRequest *instance; |
| 98 |
101 |
instance = this; |
instance = this; |
| |
| ... |
... |
PromptRequest::rlStartup() |
| 136 |
139 |
void |
void |
| 137 |
140 |
PromptRequest::rlRedisplay() |
PromptRequest::rlRedisplay() |
| 138 |
141 |
{ |
{ |
|
142 |
|
if (onInputChanged && rl_line_buffer != lastValue) { |
|
143 |
|
onInputChanged(toWide(rl_line_buffer)); |
|
144 |
|
lastValue = rl_line_buffer; |
|
145 |
|
} |
|
146 |
|
|
| 139 |
147 |
std::wstring prompt = toWide(rl_display_prompt); |
std::wstring prompt = toWide(rl_display_prompt); |
| 140 |
148 |
std::wstring beforeCursor = toWide({ rl_line_buffer, |
std::wstring beforeCursor = toWide({ rl_line_buffer, |
| 141 |
149 |
rl_line_buffer + rl_point }); |
rl_line_buffer + rl_point }); |
| File src/PromptRequest.hpp changed (mode: 100644) (index ad27139..f05c09f) |
| 19 |
19 |
#ifndef PIPEDIAL__PROMPTREQUEST_HPP__ |
#ifndef PIPEDIAL__PROMPTREQUEST_HPP__ |
| 20 |
20 |
#define PIPEDIAL__PROMPTREQUEST_HPP__ |
#define PIPEDIAL__PROMPTREQUEST_HPP__ |
| 21 |
21 |
|
|
|
22 |
|
#include <functional> |
| 22 |
23 |
#include <string> |
#include <string> |
| 23 |
24 |
#include <vector> |
#include <vector> |
| 24 |
25 |
|
|
| |
| ... |
... |
private: |
| 58 |
59 |
// Provides text editing facility via prompt. |
// Provides text editing facility via prompt. |
| 59 |
60 |
class PromptRequest |
class PromptRequest |
| 60 |
61 |
{ |
{ |
|
62 |
|
// Type of callback function invoked when input is changed. |
|
63 |
|
using inputChangedFunc = std::function<void(const std::wstring &newInput)>; |
|
64 |
|
|
| 61 |
65 |
public: |
public: |
| 62 |
66 |
// Remembers arguments and makes cursor visible. |
// Remembers arguments and makes cursor visible. |
| 63 |
67 |
PromptRequest(cursed::Input &input, cursed::Screen &screen, |
PromptRequest(cursed::Input &input, cursed::Screen &screen, |
| 64 |
|
cursed::Prompt &promptArea); |
|
|
68 |
|
cursed::Prompt &promptArea, |
|
69 |
|
inputChangedFunc onInputChanged = {}); |
| 65 |
70 |
// Cleans up and hides cursor. |
// Cleans up and hides cursor. |
| 66 |
71 |
~PromptRequest(); |
~PromptRequest(); |
| 67 |
72 |
|
|
| |
| ... |
... |
private: |
| 94 |
99 |
void updateScreen(); |
void updateScreen(); |
| 95 |
100 |
|
|
| 96 |
101 |
private: |
private: |
| 97 |
|
cursed::Input &input; // Source of input events. |
|
| 98 |
|
cursed::Screen &screen; // Screen manager. |
|
| 99 |
|
cursed::Prompt &promptArea; // Widget that displays the prompt. |
|
| 100 |
|
std::string initialValue; // Initial value of the prompt. |
|
| 101 |
|
std::vector<int> inputBuf; // Input queue. |
|
|
102 |
|
cursed::Input &input; // Source of input events. |
|
103 |
|
cursed::Screen &screen; // Screen manager. |
|
104 |
|
cursed::Prompt &promptArea; // Widget that displays the prompt. |
|
105 |
|
inputChangedFunc onInputChanged; // Callback invoked when input is changed. |
|
106 |
|
std::string initialValue; // Initial value of the prompt. |
|
107 |
|
std::string lastValue; // Last seen input value. |
|
108 |
|
std::vector<int> inputBuf; // Input queue. |
| 102 |
109 |
}; |
}; |
| 103 |
110 |
|
|
| 104 |
111 |
#endif // PIPEDIAL__PROMPTREQUEST_HPP__ |
#endif // PIPEDIAL__PROMPTREQUEST_HPP__ |