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

46 lines
1.0 KiB
C++
Raw Normal View History

#ifndef READLINE_HPP
#define READLINE_HPP
#include <string>
#include <string_view>
#include <mutex>
2023-05-19 00:23:23 -04:00
#include "drvutil.hpp"
class ReadlineDevice {
public:
2023-05-19 00:23:23 -04:00
using print_callback = void (*)(const std::u32string &text);
private:
std::mutex mutex_;
2023-05-19 00:23:23 -04:00
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:
// 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