Lots of work on unicode support
This commit is contained in:
@@ -4,19 +4,19 @@
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "drvutil.hpp"
|
||||
|
||||
using CodepointString = std::basic_string<char32_t>;
|
||||
|
||||
class ReadlineDevice {
|
||||
public:
|
||||
using print_callback = void (*)(const CodepointString &text);
|
||||
using print_callback = void (*)(const std::u32string &text);
|
||||
|
||||
private:
|
||||
print_callback print_cb_;
|
||||
CodepointString desired_command_;
|
||||
CodepointString current_command_;
|
||||
CodepointString desired_prompt_;
|
||||
CodepointString current_prompt_;
|
||||
std::u32string desired_command_;
|
||||
std::u32string current_command_;
|
||||
std::u32string desired_prompt_;
|
||||
std::u32string current_prompt_;
|
||||
char32_t readline_lastc_;
|
||||
|
||||
void erase_command();
|
||||
@@ -24,31 +24,19 @@ private:
|
||||
|
||||
|
||||
public:
|
||||
ReadlineDevice();
|
||||
|
||||
// The callback must be set before using the readline device.
|
||||
void set_print_callback(print_callback cb);
|
||||
|
||||
// change the prompt.
|
||||
void set_prompt(const CodepointString &prompt);
|
||||
void set_prompt(const std::u32string &prompt);
|
||||
|
||||
// Use this to print anything on the console.
|
||||
void print(const CodepointString &cps);
|
||||
void print(const std::u32string &cps);
|
||||
|
||||
// Whenever the user types a character, call 'putcode'. If the code is
|
||||
// newline, this returns the line of text that was entered, including the
|
||||
// newline. Otherwise returns empty string. Backspace is handled here.
|
||||
CodepointString putcode(char32_t codepoint);
|
||||
|
||||
// This can be used to convert a codepoint string into a
|
||||
// UTF8-string.
|
||||
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, 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);
|
||||
std::u32string putcode(char32_t codepoint);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user