#ifndef READLINE_HPP #define READLINE_HPP #include #include #include "drvutil.hpp" class ReadlineDevice { public: using print_callback = void (*)(const std::u32string &text); private: print_callback print_cb_; std::u32string desired_command_; std::u32string current_command_; std::u32string desired_prompt_; std::u32string current_prompt_; char32_t readline_lastc_; void erase_command(); void echo_command(); public: // The callback must be set before using the readline device. void set_print_callback(print_callback cb); // change the prompt. void set_prompt(const std::u32string &prompt); // Use this to print anything on the console. 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. std::u32string putcode(char32_t codepoint); }; #endif // READLINE_HPP