Files
integration/luprex/cpp/drv/readline.hpp

48 lines
1.1 KiB
C++

#ifndef READLINE_HPP
#define READLINE_HPP
#include <string>
#include <string_view>
#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(std::string_view prompt);
// Use this to print anything on the console.
//
// if the string doesn't end in a newline, one will
// be automatically added.
//
void printline(std::string_view 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::string putcode(char32_t codepoint);
};
#endif // READLINE_HPP