#pragma once #include #include #include #include #include namespace Bilicraft { // Owns terminal state, never the supplied descriptors. The caller must be the // sole input reader and keep all descriptors open until destruction. Stop logger // callbacks before destruction. Control/input methods belong to the main thread; // WriteLog is safe from other threads. Do not write directly to the terminal // while split mode is active: use Out(), Err(), or WriteLog(). class TerminalConsole { public: explicit TerminalConsole(int inputFd = 0, int outputFd = 1, int errorFd = 2); ~TerminalConsole() noexcept; TerminalConsole(const TerminalConsole &) = delete; TerminalConsole &operator=(const TerminalConsole &) = delete; // Call after login. Idempotent; unsupported terminals retain plain line // input (including prompts), with no terminal control sequences generated. void Start(); bool IsSplit() const; std::optional PollLine(); bool IsEof() const; void SetInputEnabled(bool enabled); void Tick(); std::ostream &Out(); std::ostream &Err(); void WriteLog(std::string_view text, bool error = false) noexcept; private: struct Impl; std::unique_ptr impl; }; } // namespace Bilicraft