
#ifndef READLINE_HPP
#define READLINE_HPP

#include <string>
#include <string_view>
#include <mutex>
#include "drvutil.hpp"


class ReadlineDevice {
public:
    using print_callback = void (*)(const std::u32string &text);

private:
    std::mutex mutex_;
    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
