Add support for > and >> prompts with new readline
This commit is contained in:
@@ -214,6 +214,11 @@ class Driver {
|
||||
|
||||
void handle_console_input() {
|
||||
read_console_recently_ = false;
|
||||
uint32_t promptlen;
|
||||
const char *promptdata;
|
||||
engw.get_console_prompt(&engw, &promptlen, &promptdata);
|
||||
CodepointString prompt = ReadlineDevice::from_utf8(std::string_view(promptdata, promptlen), nullptr);
|
||||
readline_device_.set_prompt(prompt);
|
||||
while (true) {
|
||||
CodepointString cps = console_read();
|
||||
if (cps.size() == 0) break;
|
||||
|
||||
@@ -117,6 +117,11 @@ void ReadlineDevice::set_print_callback(print_callback cb) {
|
||||
print_cb_ = cb;
|
||||
}
|
||||
|
||||
void ReadlineDevice::set_prompt(const CodepointString &prompt) {
|
||||
desired_prompt_ = prompt;
|
||||
echo_command();
|
||||
}
|
||||
|
||||
void ReadlineDevice::erase_command() {
|
||||
int ccsize = current_prompt_.size() + current_command_.size();
|
||||
if (ccsize > 0) {
|
||||
@@ -168,6 +173,7 @@ CodepointString ReadlineDevice::putcode(char32_t c) {
|
||||
desired_command_.clear();
|
||||
current_prompt_.clear();
|
||||
current_command_.clear();
|
||||
echo_command();
|
||||
return result;
|
||||
} else if ((c == '\b') || (c == 127)) {
|
||||
int len = desired_command_.size();
|
||||
|
||||
@@ -19,8 +19,9 @@ private:
|
||||
CodepointString current_prompt_;
|
||||
char32_t readline_lastc_;
|
||||
|
||||
void echo_command();
|
||||
void erase_command();
|
||||
void echo_command();
|
||||
|
||||
|
||||
public:
|
||||
ReadlineDevice();
|
||||
@@ -30,6 +31,7 @@ public:
|
||||
|
||||
// change the prompt.
|
||||
void set_prompt(const CodepointString &prompt);
|
||||
void set_prompt_utf8(const std::string &prompt);
|
||||
|
||||
// Use this to print anything on the console.
|
||||
void print(const CodepointString &cps);
|
||||
@@ -44,8 +46,9 @@ public:
|
||||
static std::string to_utf8(const CodepointString &cps);
|
||||
|
||||
// This can be used to convert UTF8 to a codepoint string.
|
||||
// Some of the bytes may not be consumed. Returns the Codepoint
|
||||
// string and the number of bytes consumed.
|
||||
// Some of the bytes may not be consumed, if the source contains
|
||||
// a partial utf-8 sequence. Returns the Codepoint string and the
|
||||
// number of bytes consumed.
|
||||
static CodepointString from_utf8(std::string_view source, int *consumed);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user