|
kaycxx-term
C++ terminal library
|
Terminal output and input helper. More...
#include <kaycxx/term/terminal.hpp>
Public Member Functions | |
| terminal (std::ostream &stream=std::cout, ansi_mode mode=ansi_mode::automatic) | |
| Creates a terminal helper for an output stream. | |
| ~terminal () | |
| Destroys the terminal helper. | |
| terminal (terminal const &)=delete | |
| terminal & | operator= (terminal const &)=delete |
| terminal (terminal &&)=delete | |
| terminal & | operator= (terminal &&)=delete |
| template<typename T > | |
| terminal & | operator<< (T const &value) |
| Writes a raw stream value. | |
| terminal & | operator<< (sgr value) |
| Writes an SGR style command. | |
| terminal & | operator<< (color_style value) |
| Writes a foreground or background color style. | |
| terminal & | operator<< (hyperlink const &link) |
| Writes a terminal hyperlink. | |
| terminal & | operator<< (std::ostream &(*manipulator)(std::ostream &)) |
| Writes an ostream manipulator. | |
| terminal & | operator<< (std::ios &(*manipulator)(std::ios &)) |
| Writes an ios manipulator. | |
| terminal & | operator<< (std::ios_base &(*manipulator)(std::ios_base &)) |
| Writes an ios_base manipulator. | |
| void | clear_screen () |
| Clears the visible screen without moving the cursor. | |
| void | clear_screen_to_end () |
| Clears from the cursor position to the end of the screen. | |
| void | clear_screen_to_start () |
| Clears from the beginning of the screen to the cursor position. | |
| void | clear_scrollback () |
| Clears the terminal scrollback buffer when supported by the terminal. | |
| void | clear_line () |
| Clears the current line without moving the cursor. | |
| void | clear_line_to_end () |
| Clears from the cursor position to the end of the current line. | |
| void | clear_line_to_start () |
| Clears from the beginning of the current line to the cursor position. | |
| void | push_title (std::string_view title) |
| Pushes the current terminal title and sets a new title. | |
| void | pop_title () |
| Pops the previously pushed terminal title. | |
| void | hide_cursor () |
| Hides the terminal cursor. | |
| void | show_cursor () |
| Shows the terminal cursor. | |
| void | save_cursor () |
| Saves the current cursor position. | |
| void | restore_cursor () |
| Restores the previously saved cursor position. | |
| void | set_cursor_style (cursor_style style) |
| Sets the terminal cursor style. | |
| void | move_to (int column, int row) |
| Moves the cursor to an absolute position. | |
| void | move_by (int columns, int rows) |
| Moves the cursor relative to its current position. | |
| void | move_to_column (int column) |
| Moves the cursor to a column on the current row. | |
| void | enable_wrap () |
| Enables terminal autowrap mode. | |
| void | disable_wrap () |
| Disables terminal autowrap mode. | |
| void | enter_alternate_screen () |
| Enters the alternate screen buffer. | |
| void | leave_alternate_screen () |
| Leaves the alternate screen buffer. | |
| terminal_size | size () const |
| Returns the current terminal size. | |
| bool | push_input_mode (input_mode mode) |
| Pushes the current input state and applies a new input mode. | |
| bool | pop_input_mode () |
| Pops and restores the previously pushed input state. | |
| std::string | read_key () |
| Reads one key from the terminal. | |
| void | insert_line () |
| Inserts a single line at the cursor row. | |
| void | insert_lines (int lines) |
| Inserts multiple lines at the cursor row. | |
| void | delete_line () |
| Deletes a single line at the cursor row. | |
| void | delete_lines (int lines) |
| Deletes multiple lines at the cursor row. | |
| void | clear_cell () |
| Clears a cell at the cursor position. | |
| void | clear_cells (int cells) |
| Clears cells at the cursor position. | |
| void | insert_cell () |
| Inserts a blank cell at the cursor position. | |
| void | insert_cells (int cells) |
| Inserts blank cells at the cursor position. | |
| void | delete_cell () |
| Deletes a cell at the cursor position. | |
| void | delete_cells (int cells) |
| Deletes cells at the cursor position. | |
| void | set_scroll_region (int top, int bottom) |
| Sets the vertical scrolling region. | |
| void | reset_scroll_region () |
| Resets the vertical scrolling region to the whole screen. | |
| void | scroll_up () |
| Scrolls the current scrolling region up by one line. | |
| void | scroll_up (int lines) |
| Scrolls the current scrolling region up by multiple lines. | |
| void | scroll_down () |
| Scrolls the current scrolling region down by one line. | |
| void | scroll_down (int lines) |
| Scrolls the current scrolling region down by multiple lines. | |
| bool | formatting_enabled () const noexcept |
| Checks whether ANSI/VT formatting is enabled for this terminal. | |
| bool | commands_enabled () const noexcept |
| Checks whether ANSI/VT terminal commands are enabled for this terminal. | |
Terminal output and input helper.
The terminal writes ANSI/VT formatting and terminal commands when enabled and provides minimal cross-platform input mode and key reading helpers.
|
explicit |
Creates a terminal helper for an output stream.
The stream defaults to std::cout. All text and all ANSI/VT output is written to this stream. In automatic ANSI mode, the stream is used to detect terminal command support while FORCE_COLOR and NO_COLOR independently control formatting.
| stream | Output stream to write to. The stream must outlive the terminal. |
| mode | ANSI output mode. Automatic mode detects terminal commands and separately honors FORCE_COLOR and NO_COLOR for formatting. |
| void kaycxx::term::terminal::clear_cell | ( | ) |
Clears a cell at the cursor position.
The current cell is replaced with a blank cell. Text to the right is not shifted and the cursor stays at its position.
| void kaycxx::term::terminal::clear_cells | ( | int | cells | ) |
Clears cells at the cursor position.
The cells are replaced with blank cells. Text to the right is not shifted and the cursor stays at its position. Nothing is written when the cell count is zero or negative.
| cells | Number of cells to clear. |
|
noexcept |
Checks whether ANSI/VT terminal commands are enabled for this terminal.
Terminal commands include cursor movement, screen manipulation, title changes, hyperlinks, and terminal modes. Color environment variables do not affect this state.
| void kaycxx::term::terminal::delete_cell | ( | ) |
Deletes a cell at the cursor position.
Existing text to the right is shifted left within the current line.
| void kaycxx::term::terminal::delete_cells | ( | int | cells | ) |
Deletes cells at the cursor position.
Existing text to the right is shifted left within the current line. Nothing is written when the cell count is zero or negative.
| cells | Number of cells to delete. |
| void kaycxx::term::terminal::delete_lines | ( | int | lines | ) |
Deletes multiple lines at the cursor row.
Nothing is written when the line count is zero or negative.
| lines | Number of lines to delete. |
|
noexcept |
Checks whether ANSI/VT formatting is enabled for this terminal.
Formatting includes colors and SGR text styles. This returns the resolved formatting state from the constructor, not the raw ansi_mode value.
| void kaycxx::term::terminal::insert_cell | ( | ) |
Inserts a blank cell at the cursor position.
Existing text to the right is shifted right within the current line.
| void kaycxx::term::terminal::insert_cells | ( | int | cells | ) |
Inserts blank cells at the cursor position.
Existing text to the right is shifted right within the current line. Nothing is written when the cell count is zero or negative.
| cells | Number of cells to insert. |
| void kaycxx::term::terminal::insert_lines | ( | int | lines | ) |
Inserts multiple lines at the cursor row.
Nothing is written when the line count is zero or negative.
| lines | Number of lines to insert. |
| void kaycxx::term::terminal::move_by | ( | int | columns, |
| int | rows | ||
| ) |
Moves the cursor relative to its current position.
Positive columns move right, negative columns move left. Positive rows move down, negative rows move up.
| columns | Relative column movement. |
| rows | Relative row movement. |
| void kaycxx::term::terminal::move_to | ( | int | column, |
| int | row | ||
| ) |
Moves the cursor to an absolute position.
Coordinates are one-based terminal coordinates.
| column | Target column. |
| row | Target row. |
| void kaycxx::term::terminal::move_to_column | ( | int | column | ) |
Moves the cursor to a column on the current row.
| column | Target column. |
| terminal & kaycxx::term::terminal::operator<< | ( | color_style | value | ) |
Writes a foreground or background color style.
| value | Color style to write. |
Writes a terminal hyperlink.
| link | Hyperlink to write. |
Writes an SGR style command.
| value | SGR command to write. |
| terminal & kaycxx::term::terminal::operator<< | ( | std::ios &(*)(std::ios &) | manipulator | ) |
Writes an ios manipulator.
| manipulator | Manipulator to apply. |
| terminal & kaycxx::term::terminal::operator<< | ( | std::ios_base &(*)(std::ios_base &) | manipulator | ) |
Writes an ios_base manipulator.
| manipulator | Manipulator to apply. |
| terminal & kaycxx::term::terminal::operator<< | ( | std::ostream &(*)(std::ostream &) | manipulator | ) |
Writes an ostream manipulator.
| manipulator | Manipulator to apply. |
|
inline |
Writes a raw stream value.
This overload forwards the value unchanged to the wrapped stream.
| T | Value type to write. |
| value | Value to write. |
| bool kaycxx::term::terminal::pop_input_mode | ( | ) |
Pops and restores the previously pushed input state.
| bool kaycxx::term::terminal::push_input_mode | ( | input_mode | mode | ) |
Pushes the current input state and applies a new input mode.
| mode | Input mode to apply. |
| void kaycxx::term::terminal::push_title | ( | std::string_view | title | ) |
Pushes the current terminal title and sets a new title.
| title | New terminal title. |
| std::string kaycxx::term::terminal::read_key | ( | ) |
Reads one key from the terminal.
The returned string contains the raw key byte sequence. POSIX terminals return their native byte sequences. Windows console key events are mapped to POSIX-style escape sequences for cursor and function keys.
| void kaycxx::term::terminal::scroll_down | ( | int | lines | ) |
Scrolls the current scrolling region down by multiple lines.
Nothing is written when the line count is zero or negative.
| lines | Number of lines to scroll. |
| void kaycxx::term::terminal::scroll_up | ( | int | lines | ) |
Scrolls the current scrolling region up by multiple lines.
Nothing is written when the line count is zero or negative.
| lines | Number of lines to scroll. |
| void kaycxx::term::terminal::set_cursor_style | ( | cursor_style | style | ) |
Sets the terminal cursor style.
| style | Cursor style to apply. |
| void kaycxx::term::terminal::set_scroll_region | ( | int | top, |
| int | bottom | ||
| ) |
Sets the vertical scrolling region.
Coordinates are one-based terminal rows. Nothing is written when the range is invalid.
| top | First row in the scrolling region. |
| bottom | Last row in the scrolling region. |
| terminal_size kaycxx::term::terminal::size | ( | ) | const |
Returns the current terminal size.