#pragma once #include #include namespace roro { // Single-line UTF-8 text editing. The cursor is a byte index always on a character boundary, // and the text never exceeds maxBytes (protocol fields are limited in bytes, not characters). class LineEditor { public: explicit LineEditor(size_t maxBytes) : max_(maxBytes) {} void setText(const std::string& text); // truncates, cursor to end const std::string& text() const { return text_; } size_t cursor() const { return cursor_; } size_t maxBytes() const { return max_; } bool insert(uint32_t codePoint); // false if it would not fit void backspace(); void left(); void right(); void home() { cursor_ = 0; } void end() { cursor_ = text_.size(); } private: size_t max_; std::string text_; size_t cursor_ = 0; }; } // namespace roro