#pragma once #include "common.hpp" // OS-specific libraries. #include // Scope object to hide the cursor. This avoids // cursor twinkling when rewritting the same line // too frequently. // If you are within a cursor_hider context you can // reenable the cursor using cursor_hider(false). class cursor_hider : noncopyable_nonmovable { public: cursor_hider(bool hide = true); ~cursor_hider(); private: void write_ansi_code(bool hide); bool m_hide; static unsigned int s_scope_count; }; // Scope object to use alternative output buffer for // fullscreen interactive terminal input/output. class alternative_buffer : noncopyable_nonmovable { public: alternative_buffer(); ~alternative_buffer(); private: struct termios m_previous_termios; }; // Scope object to control echo of stdin to stdout. // This should be disabled when entering passwords for example. class echo_control : noncopyable_nonmovable { public: echo_control(bool echo); ~echo_control(); private: bool m_echo; struct termios m_previous_termios; }; // Display a prompt on stdout and return newline-terminated input received on // stdin from the user. The `echo` argument controls whether stdin is echoed // to stdout, use `false` for passwords. std::string prompt_input(const std::string_view prompt, bool echo = true); // Display a prompt on stdout and accept a yes or no answer on stdin. // Return true if the first character on stdin is 'y' or 'Y', false if it is // 'n' or 'N', or default_return if the input is empty which occurs if the user // presses enter only. Otherwise the input is ambiguous so repeat the prompt. bool prompt_yes_or_no(const std::string_view prompt, bool default_return);