### Custom Key Binding Setup Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/key.md Demonstrates setting up custom key bindings using a map where keys are `Term::Key` objects (potentially combined with modifiers) and values are functions to be executed when the key is pressed. Includes examples for F1, Ctrl+S, and Ctrl+Q. ```cpp #include "cpp-terminal/key.hpp" #include #include std::map> bindings; void setup_keybindings() { bindings[Term::Key::F1] = [](){ /* Show help */ }; bindings[Term::MetaKey::Ctrl + Term::Key::S] = [](){ /* Save */ }; bindings[Term::MetaKey::Ctrl + Term::Key::Q] = [](){ /* Quit */ }; } void dispatch_key(const Term::Key& key) { auto it = bindings.find(key); if (it != bindings.end()) { it->second(); } } ``` -------------------------------- ### Example: Initialize and Use Screen Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/screen.md Demonstrates creating a Screen object with specific dimensions and accessing its properties. ```cpp Term::Screen screen(Term::Size(Term::Rows(24), Term::Columns(80))); ``` ```cpp std::size_t height = static_cast(screen.rows()); ``` ```cpp std::size_t width = static_cast(screen.columns()); ``` ```cpp if (screen.empty()) { // Invalid or uninitialized screen } ``` -------------------------------- ### Basic Hello World with Color Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/README.md A simple example demonstrating how to print 'Hello, World!' to the console with foreground color. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/color.hpp" #include int main() { std::cout << Term::color_fg(Term::Color::Name::Red) << "Hello, World!" << Term::color_fg(Term::Color::Name::Default) << "\n"; return 0; } ``` -------------------------------- ### Complete TUI Setup with Options Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Demonstrates a full Text User Interface (TUI) setup using cpp-terminal. It configures terminal options for raw mode, screen clearing, cursor hiding, and signal key handling, then proceeds to create a basic TUI window and event loop. The terminal state is automatically restored upon exiting the application. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/options.hpp" #include "cpp-terminal/screen.hpp" #include "cpp-terminal/window.hpp" #include "cpp-terminal/input.hpp" #include "cpp-terminal/event.hpp" #include int main() { try { // Configure for full-screen TUI Term::terminal.setOptions( Term::Option::Raw, Term::Option::ClearScreen, Term::Option::NoCursor, Term::Option::NoSignalKeys ); // Verify configuration Term::Options config = Term::terminal.getOptions(); if (!config.has(Term::Option::Raw)) { std::cerr << "Failed to set raw mode\n"; return 1; } // Get screen size Term::Screen screen = Term::screen_size(); Term::Window window(screen); // Application loop window.print_border(); window.print_str(2, 2, "TUI Application"); std::cout << window.render(0, 0, true); std::cout << std::flush; // Wait for input while (true) { Term::Event event = Term::read_event(); if (auto* key = event.get_if_key()) { if (*key == (Term::MetaKey::Ctrl + Term::Key::Q)) { break; } } } } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << "\n"; return 1; } // Terminal state automatically restored here return 0; } ``` -------------------------------- ### Runtime Version Verification Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Demonstrates how to check the runtime version of cpp-terminal to ensure compatibility. ```APIDOC ## Runtime Version Verification ### Description This example shows how to verify the cpp-terminal version at runtime to ensure that the application has the required version or higher. ### Example ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::uint16_t major = Term::Version::major(); if (major < 3) { std::cerr << "This application requires cpp-terminal 3.0 or later\n"; std::cerr << "Found version: " << Term::Version::string() << "\n"; return 1; } std::cout << "Using cpp-terminal " << Term::Version::string() << "\n"; return 0; } ``` ``` -------------------------------- ### Quality Standard: Usage Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/MANIFEST.md Requires a real code example demonstrating typical usage of the documented symbol. ```markdown ✅ **Usage Example** — Real code showing typical usage ``` -------------------------------- ### Version String Formatting Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Demonstrates how to format the cpp-terminal version information into a custom string. ```APIDOC ## Version String Formatting ### Description This example shows how to combine the major, minor, and patch version numbers along with the project homepage into a single, informative string using `std::ostringstream`. ### Example ```cpp #include "cpp-terminal/version.hpp" #include #include std::string get_version_info() { std::ostringstream oss; oss << "cpp-terminal " << Term::Version::major() << "." << Term::Version::minor() << "." << Term::Version::patch() << " (" << Term::homepage() << ")"; return oss.str(); } int main() { std::cout << get_version_info() << "\n"; return 0; } ``` ``` -------------------------------- ### Example: Constructing MetaKey objects Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/key.md Demonstrates how to create MetaKey objects for Ctrl and Alt modifiers using their respective values. ```cpp Term::MetaKey ctrl(Term::MetaKey::Value::Ctrl); Term::MetaKey alt(Term::MetaKey::Value::Alt); ``` -------------------------------- ### Display Program Info Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Shows how to display application information including the cpp-terminal version and project homepage. ```APIDOC ## Display Program Info ### Description This example shows how to create an 'About' dialog or section that displays the application's version along with the version and homepage of its dependency, cpp-terminal. ### Example ```cpp #include "cpp-terminal/version.hpp" #include void show_about() { std::cout << "====================================\n"; std::cout << "MyApplication v1.0\n"; std::cout << "Built with cpp-terminal " << Term::Version::string() << "\n"; std::cout << "Project: " << Term::homepage() << "\n"; std::cout << "====================================\n"; } int main() { show_about(); return 0; } ``` ``` -------------------------------- ### Create C++ Terminal Example CMake Function Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/examples/CMakeLists.txt Defines a CMake function `cppterminal_example` to streamline the creation of executable examples. It handles adding executables, linking necessary libraries (including `cpp-terminal` and warning configurations), and optionally installing them. ```cmake function(cppterminal_example) cmake_parse_arguments(ARG "WIN32" "SOURCE" "LIBRARIES" ${ARGN}) if(ARG_WIN32) add_executable("${ARG_SOURCE}" WIN32 "${ARG_SOURCE}.cpp") else() add_executable("${ARG_SOURCE}" "${ARG_SOURCE}.cpp") endif() target_link_libraries("${ARG_SOURCE}" PRIVATE cpp-terminal::cpp-terminal Warnings::Warnings Warnings::Examples) if(DEFINED ARG_LIBRARIES) target_link_libraries("${ARG_SOURCE}" PRIVATE "${ARG_LIBRARIES}") endif() if(CPPTERMINAL_ENABLE_INSTALL) install(TARGETS "${ARG_SOURCE}" RUNTIME DESTINATION bin/examples) endif() endfunction() ``` -------------------------------- ### Example: Combining MetaKey modifiers Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/key.md Demonstrates combining Ctrl and Alt modifier values to create a MetaKey object representing both. ```cpp Term::MetaKey both = Term::MetaKey::Value::Ctrl + Term::MetaKey::Value::Alt; ``` -------------------------------- ### List of C++ Terminal Examples Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/examples/CMakeLists.txt Calls the `cppterminal_example` function to define various example executables. Each call specifies the source file name and, in some cases, additional libraries or platform-specific flags (like WIN32). ```cmake cppterminal_example(SOURCE args) cppterminal_example(SOURCE cin_cooked) cppterminal_example(SOURCE cin_raw) cppterminal_example(SOURCE colors) cppterminal_example(SOURCE cursor) cppterminal_example(SOURCE cout) cppterminal_example(SOURCE events LIBRARIES Threads::Threads) cppterminal_example(SOURCE keys) cppterminal_example(SOURCE kilo) cppterminal_example(SOURCE menu) cppterminal_example(SOURCE menu_window) cppterminal_example(SOURCE minimal) cppterminal_example(SOURCE prompt_immediate) cppterminal_example(SOURCE prompt_multiline) cppterminal_example(SOURCE prompt_not_immediate) cppterminal_example(SOURCE prompt_simple) cppterminal_example(SOURCE styles) cppterminal_example(SOURCE utf8) cppterminal_example(SOURCE signal) cppterminal_example(SOURCE attach_console WIN32) cppterminal_example(SOURCE attach_console_minimal WIN32) ``` -------------------------------- ### Interactive Configuration Menu with C++ Terminal Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/prompt.md Demonstrates how to create an interactive configuration menu using Term::prompt_simple and Term::prompt. This example includes basic input for username and confirmation of settings. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/prompt.hpp" #include #include int main() { Term::terminal.setOptions(Term::Option::Raw); std::string username; std::string password; bool confirmed = false; // Get username while (true) { Term::Result_simple result = Term::prompt_simple("Enter username"); if (result == Term::Result_simple::Yes) { // In real usage, capture the actual input from the prompt username = "user"; break; } else if (result == Term::Result_simple::Abort) { std::cout << "Setup cancelled\n"; return 1; } } // Confirm settings while (true) { Term::Result result = Term::prompt( "Confirm username: " + username, "yes", "no", ": ", false ); if (result == Term::Result::Yes) { confirmed = true; break; } else if (result == Term::Result::No) { std::cout << "Try again\n"; continue; } else if (result == Term::Result::Abort) { return 1; } } if (confirmed) { std::cout << "Configuration saved\n"; } return 0; } ``` -------------------------------- ### Get Key as String Representation Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/key.md Use `str()` to get the string representation of the key. This method provides a raw string output of the key. ```cpp std::string str() const ``` -------------------------------- ### Blinking Text Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Provides examples for applying blinking text effects using Term::Style::Blink and Term::Style::BlinkRapid. Note that blinking may be ignored by many terminals for accessibility reasons. ```APIDOC ### Blinking Text ```cpp #include "cpp-terminal/style.hpp" #include int main() { // Slow blink (less than 150 bpm) std::cout << Term::style(Term::Style::Blink) << "Blinking" << Term::style(Term::Style::ResetBlink) << "\n"; // Rapid blink (may not work on most terminals) std::cout << Term::style(Term::Style::BlinkRapid) << "Rapid blink" << Term::style(Term::Style::ResetBlinkRapid) << "\n"; // Note: Many terminals ignore blink for accessibility return 0; } ``` ``` -------------------------------- ### Combining Styles with Colors Examples Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Illustrates how to combine text styles with foreground and background colors for more advanced text formatting. ```APIDOC ### Combining Styles with Colors ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/color.hpp" #include "cpp-terminal/style.hpp" #include int main() { // Bold red text std::cout << Term::style(Term::Style::Bold) << Term::color_fg(Term::Color::Name::Red) << "IMPORTANT" << Term::style(Term::Style::Reset) << "\n"; // Underlined blue text std::cout << Term::style(Term::Style::Underline) << Term::color_fg(Term::Color::Name::Blue) << "Link" << Term::style(Term::Style::Reset) << "\n"; // Italic yellow on black background std::cout << Term::style(Term::Style::Italic) << Term::color_fg(255, 255, 0) << Term::color_bg(0, 0, 0) << "Italic text" << Term::style(Term::Style::Reset) << "\n"; return 0; } ``` ``` -------------------------------- ### Complete Window Example in C++ Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/window.md This snippet shows how to create a window, fill its background, draw a border, add a title and text, and render it to the terminal. It requires including several headers from the cpp-terminal library. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/window.hpp" #include "cpp-terminal/color.hpp" #include "cpp-terminal/style.hpp" #include "cpp-terminal/screen.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); // Create window Term::Screen screen = Term::screen_size(); Term::Window window(screen); // Fill background window.fill_bg(0, 0, 80, 24, Term::Color(34, 139, 34)); // Draw border window.print_border(); // Add title window.set_style(10, 1, Term::Style::Bold); window.set_fg(10, 1, Term::Color(Term::Color::Name::White)); window.print_str(10, 1, "My Application"); // Draw a box window.print_rect(5, 5, 30, 10); // Add text in box window.set_fg(7, 7, Term::Color(Term::Color::Name::Yellow)); window.print_str(7, 7, "Press ESC to exit"); // Render to terminal std::cout << window.render(0, 0, true); // Event loop (simplified) std::cout << std::flush; return 0; } ``` -------------------------------- ### Version String Formatting Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Formats the cpp-terminal version and homepage into a single string using string streams. Useful for custom logging or display formats. ```cpp #include "cpp-terminal/version.hpp" #include #include std::string get_version_info() { std::ostringstream oss; oss << "cpp-terminal " << Term::Version::major() << "." << Term::Version::minor() << "." << Term::Version::patch() << " (" << Term::homepage() << ")"; return oss.str(); } int main() { std::cout << get_version_info() << "\n"; return 0; } ``` -------------------------------- ### Window-Based Styling Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Demonstrates how to apply styles to specific regions of a terminal window using the Term::Window class, including filling areas with styles and setting individual cell styles and colors. ```APIDOC ### Window-Based Styling ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/window.hpp" #include "cpp-terminal/screen.hpp" #include "cpp-terminal/style.hpp" #include "cpp-terminal/color.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); Term::Screen screen = Term::screen_size(); Term::Window window(screen); // Set entire window styles window.fill_style(0, 0, 80, 5, Term::Style::Bold); window.fill_style(0, 5, 80, 10, Term::Style::Dim); window.fill_style(0, 10, 80, 15, Term::Style::Underline); // Combine with colors window.set_fg(10, 2, Term::Color(Term::Color::Name::Red)); window.set_style(10, 2, Term::Style::Bold); window.print_str(10, 2, "Bold Red Header"); std::cout << window.render(0, 0, true); std::cout << std::flush; return 0; } ``` ``` -------------------------------- ### Retrieve Current Terminal Options Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/terminal.md Get the current options configuration of the Terminal instance. ```cpp Term::Options current = Term::terminal.getOptions(); ``` -------------------------------- ### Feature Availability Based on Version Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Illustrates how to conditionally enable features based on the cpp-terminal version. ```APIDOC ## Feature Availability Based on Version ### Description This example demonstrates how to check the major and minor versions of cpp-terminal to enable or disable specific features based on version compatibility. ### Example ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::uint16_t major = Term::Version::major(); std::uint16_t minor = Term::Version::minor(); std::cout << "Version " << major << "." << minor << "\n"; // Example: feature availability logic if (major > 3 || (major == 3 && minor >= 2)) { std::cout << "Advanced features available\n"; } else { std::cout << "Using basic feature set\n"; } return 0; } ``` ``` -------------------------------- ### Reversed Colors (Inverse) Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Shows how to use the Term::Style::Reversed style to invert the foreground and background colors of the text. ```APIDOC ### Reversed Colors (Inverse) ```cpp #include "cpp-terminal/color.hpp" #include "cpp-terminal/style.hpp" #include int main() { // Normal: blue FG on default BG std::cout << Term::color_fg(Term::Color::Name::Blue) << "Normal blue" << "\n"; // Reversed: default FG on blue BG (visual inversion) std::cout << Term::style(Term::Style::Reversed) << Term::color_fg(Term::Color::Name::Blue) << "Reversed blue" << Term::style(Term::Style::Reset) << "\n"; return 0; } ``` ``` -------------------------------- ### Initialize Terminal for Input Reading Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/input.md Shows the basic setup required before calling `read_event()`. The Terminal singleton must be initialized, which happens automatically when `terminal.hpp` is included. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/input.hpp" int main() { // Terminal automatically initialized when terminal.hpp is included // Now read_event() will work Term::Event event = Term::read_event(); return 0; } ``` -------------------------------- ### Class API Reference Entry Format Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/MANIFEST.md This outlines the structure for documenting classes, including an overview, constructor, methods, operators, and a usage example. ```markdown #### For Classes: 1. Overview paragraph 2. Constructor documentation 3. Method documentation (grouped by purpose) 4. Operator documentation 5. Complete usage example 6. Source file reference ``` -------------------------------- ### Basic Text Formatting Examples Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Demonstrates the usage of the Term::style function to apply basic text formatting such as bold, underline, italic, strikethrough, dim, and reset. ```APIDOC ### Basic Text Formatting ```cpp #include "cpp-terminal/style.hpp" #include int main() { // Bold text std::cout << Term::style(Term::Style::Bold) << "Bold text" << Term::style(Term::Style::ResetBold) << "\n"; // Underlined text std::cout << Term::style(Term::Style::Underline) << "Underlined" << Term::style(Term::Style::ResetUnderline) << "\n"; // Italic text std::cout << Term::style(Term::Style::Italic) << "Italic" << Term::style(Term::Style::ResetItalic) << "\n"; // Strikethrough std::cout << Term::style(Term::Style::Crossed) << "Strikethrough" << Term::style(Term::Style::ResetCrossed) << "\n"; // Dim text std::cout << Term::style(Term::Style::Dim) << "Dim/faint" << Term::style(Term::Style::ResetDim) << "\n"; // Reset all std::cout << Term::style(Term::Style::Reset) << "Back to default\n"; return 0; } ``` ``` -------------------------------- ### Custom Prompt with Non-Standard Options in C++ Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/prompt.md Illustrates how to use Term::prompt with custom option names and a prompt indicator. This example shows how to handle 'save' and 'discard' options for user confirmation. ```cpp #include "cpp-terminal/prompt.hpp" #include int main() { // Use custom option names Term::Result result = Term::prompt( "Save changes before exiting?", "save", // first_option "discard", // second_option " > ", // prompt_indicator false // require Enter ); switch (result) { case Term::Result::Yes: std::cout << "Saving...\n"; break; case Term::Result::No: std::cout << "Discarding...\n"; break; case Term::Result::Abort: std::cout << "Cancelled\n"; break; default: break; } return 0; } ``` -------------------------------- ### Complete Color Example in C++ Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/color.md Use this snippet to display text with different color formats, including 3-bit, 24-bit true color, and 8-bit palette colors. It also shows how to set background colors and reset them to default. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/color.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); // 3-bit colors std::cout << Term::color_fg(Term::Color::Name::Red) << "Red text\n"; std::cout << Term::color_fg(Term::Color::Name::BrightGreen) << "Bright green text\n"; // 24-bit true color std::cout << Term::color_fg(255, 128, 0) << "Orange text\n"; // 8-bit palette std::cout << Term::color_fg(196) << "Palette color 196\n"; // Background colors std::cout << Term::color_bg(34, 139, 34) << " Green background " << Term::color_bg(Term::Color::Name::Default) << "\n"; // Reset to defaults std::cout << Term::color_fg(Term::Color::Name::Default); return 0; } ``` -------------------------------- ### Basic Focus Detection Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/focus.md Demonstrates how to read terminal events and react to focus changes (gained or lost). Exits the loop when the Escape key is pressed. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/input.hpp" #include "cpp-terminal/event.hpp" #include "cpp-terminal/focus.hpp" #include "cpp-terminal/color.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw); bool window_focused = true; while (true) { Term::Event event = Term::read_event(); if (auto* focus = event.get_if_focus()) { if (focus->in()) { std::cout << Term::color_fg(Term::Color::Name::Green) << "Window gained focus\n"; window_focused = true; } else if (focus->out()) { std::cout << Term::color_fg(Term::Color::Name::Yellow) << "Window lost focus\n"; window_focused = false; } else { std::cout << "Focus state unknown\n"; } } else if (auto* key = event.get_if_key()) { if (*key == Term::Key::Esc) { break; } } } return 0; } ``` -------------------------------- ### Runtime Version Verification Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Checks if the runtime version of cpp-terminal meets the minimum required major version. Logs an error and exits if the version is insufficient. ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::uint16_t major = Term::Version::major(); if (major < 3) { std::cerr << "This application requires cpp-terminal 3.0 or later\n"; std::cerr << "Found version: " << Term::Version::string() << "\n"; return 1; } std::cout << "Using cpp-terminal " << Term::Version::string() << "\n"; return 0; } ``` -------------------------------- ### Create Cursor at Default Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/cursor.md Initializes a cursor at the default position (1, 1). Use this when no specific starting position is required. ```cpp Term::Cursor default_position; ``` -------------------------------- ### Switching Between Raw and Cooked Terminal Modes Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Demonstrates how to start in raw mode and then switch to cooked mode using an escape key press. This allows for dynamic adjustment of terminal input handling during application runtime. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/options.hpp" #include "cpp-terminal/input.hpp" #include "cpp-terminal/event.hpp" #include int main() { // Start in raw mode Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); std::cout << "In raw mode (ESC to switch to cooked)\n"; std::cout << std::flush; Term::Event event = Term::read_event(); if (auto* key = event.get_if_key()) { if (*key == Term::Key::Esc) { // Switch to cooked mode Term::terminal.setOptions(Term::Option::Cooked); std::cout << "Switched to cooked mode\n"; } } return 0; } ``` -------------------------------- ### Type Conversion and Assignment Example Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/types.md Demonstrates constructing type-safe wrappers from base types, using assignment operators, and performing explicit conversions back to their base types. This pattern applies to all enums and type-safe wrappers. ```cpp Term::Rows rows(24); std::size_t count = static_cast(rows); Term::Key key(Term::Key::F1); std::int32_t value = static_cast(key); ``` -------------------------------- ### Read Terminal Events with read_event() Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/input.md This example demonstrates how to continuously read terminal events and process key presses. It blocks until an event is available and skips empty events. ```cpp #include "cpp-terminal/input.hpp" #include "cpp-terminal/event.hpp" #include int main() { while (true) { Term::Event event = Term::read_event(); if (event.empty()) { continue; } if (auto* key = event.get_if_key()) { std::cout << "Key: " << key->name() << "\n"; } } return 0; } ``` -------------------------------- ### Suppress Example Warnings CMake Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/examples/CMakeLists.txt Defines an interface library to suppress specific compiler warnings for examples, while allowing them for the main cpp-terminal library. This ensures cleaner output during example builds. ```cmake add_library(ExamplesWarnings INTERFACE) target_compile_options( ExamplesWarnings INTERFACE $<$:/wd4061 /utf-8 /wd4668> $<$:/wd4061 /utf-8 /wd4668> ) add_library(Warnings::Examples ALIAS ExamplesWarnings) ``` -------------------------------- ### Window Rendering and Styling Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/README.md Demonstrates creating a window, printing strings, setting cell colors and styles, and rendering the window content to the terminal. ```cpp Term::Screen screen = Term::screen_size(); Term::Window window(screen); window.print_str(0, 0, "Hello"); window.set_fg(0, 0, Term::Color(Term::Color::Name::Green)); window.set_style(0, 0, Term::Style::Bold); std::cout << window.render(0, 0, true); ``` -------------------------------- ### Get Current Cursor Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/cursor.md Queries the terminal for the current cursor position and blocks until a response is received. This is the recommended way to get the cursor's location. ```cpp Term::Cursor cursor_position() Term::Cursor current = Term::cursor_position(); std::cout << "Current position: (" << current.row() << ", " << current.column() << ")\n" ``` -------------------------------- ### Terminal Initialization Options Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/README.md Demonstrates setting terminal options such as Raw mode, clearing the screen, and hiding the cursor during initialization. ```cpp Term::terminal.setOptions( Term::Option::Raw, // Raw mode (no line buffering) Term::Option::ClearScreen, // Clear screen on startup/exit Term::Option::NoCursor // Hide cursor ); ``` -------------------------------- ### Function API Reference Entry Format Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/MANIFEST.md This details the structure for documenting functions, including signature, parameter table, return type, exceptions, and a minimal code example. ```markdown #### For Functions: 1. Function signature (code block) 2. Parameter table (name, type, required, default, description) 3. Return type documentation 4. Exceptions that may be thrown 5. Minimal code example 6. Source location ``` -------------------------------- ### Get Cursor Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/cursor.md Shows how to retrieve the current position of the cursor. ```APIDOC ## Get Cursor Position ### Description Retrieves the current row and column of the cursor. ### Function - **cursor_position()**: Returns a `Term::Cursor` object representing the current cursor position. ### Example ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/cursor.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw); // Get current position Term::Cursor pos = Term::cursor_position(); std::cout << Term::cursor_move(1, 1); std::cout << "Cursor at: (" << pos.row() << ", " << pos.column() << ")"; std::cout << std::flush; return 0; } ``` ``` -------------------------------- ### Color Initialization and Usage Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/README.md Illustrates creating colors by name, index, or RGB values and applying them as foreground colors to text. ```cpp Term::Color by_name(Term::Color::Name::Red); Term::Color by_index(196); // 8-bit palette Term::Color by_rgb(255, 0, 0); // 24-bit RGB std::cout << Term::color_fg(by_rgb) << "Red text\n"; ``` -------------------------------- ### Get Window Height Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/window.md Retrieves the current height (number of rows) of the window. ```cpp std::size_t height = static_cast(window.rows()); ``` -------------------------------- ### Get Window Width Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/window.md Retrieves the current width (number of columns) of the window. ```cpp std::size_t width = static_cast(window.columns()); ``` -------------------------------- ### Options Constructors Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Demonstrates how to create and initialize Options objects using different constructor overloads. ```APIDOC ## Options Constructors ### Options() Create empty options (no configuration set). **Example:** ```cpp Term::Options defaults; ``` ### Options(const std::initializer_list& option) Create options from initializer list. | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | option | `std::initializer_list` | yes | — | List of options | **Example:** ```cpp Term::Options opts({Term::Option::Raw, Term::Option::NoCursor}); ``` ### Options(const Args&&... args) Create options from variadic arguments. | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | args | `Term::Option...` | yes | — | Variable-length option list | **Example:** ```cpp Term::Options opts(Term::Option::Raw, Term::Option::ClearScreen, Term::Option::NoCursor); ``` ``` -------------------------------- ### Get Mouse Column Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/mouse.md Retrieves the column coordinate of the mouse event. The column is 0-based. ```cpp std::size_t column() const noexcept ``` -------------------------------- ### Create Responsive Layout with Screen Size Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/screen.md Demonstrates creating a window that matches the current terminal size and filling it with a pattern. This is a foundation for responsive TUI applications. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/screen.hpp" #include "cpp-terminal/window.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); // Get current screen size Term::Screen screen = Term::screen_size(); if (screen.empty()) { std::cerr << "Failed to get terminal size\n"; return 1; } // Create window matching screen size Term::Window window(screen); // Fill with a pattern window.fill_bg(0, 0, static_cast(window.columns()), static_cast(window.rows()), Term::Color(34, 139, 34)); window.print_border(); // Render std::cout << window.render(0, 0, true); std::cout << std::flush; sleep(2); return 0; } ``` -------------------------------- ### Get Mouse Row Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/mouse.md Retrieves the row coordinate of the mouse event. The row is 0-based. ```cpp std::cout << "Mouse at row " << mouse.row(); ``` -------------------------------- ### Basic Hello World with ANSI Color Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/README.md Demonstrates printing colored text using ANSI escape codes by including the main terminal header. This method relies on the terminal's support for ANSI sequences. ```cpp #include "cpp-terminal/terminal.hpp" #include int main() { std::cout << "Just including terminal.hpp activate \033[31mcolor\033[0m !" << std::endl; } ``` -------------------------------- ### Window-Based Styling with Styles and Colors Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Illustrates how to apply styles and colors to specific regions within a terminal window using `Term::Window`. This allows for complex UI layouts and targeted formatting. ```cpp #include "cpp-terminal/terminal.hpp" #include "cpp-terminal/window.hpp" #include "cpp-terminal/screen.hpp" #include "cpp-terminal/style.hpp" #include "cpp-terminal/color.hpp" #include int main() { Term::terminal.setOptions(Term::Option::Raw, Term::Option::ClearScreen); Term::Screen screen = Term::screen_size(); Term::Window window(screen); // Set entire window styles window.fill_style(0, 0, 80, 5, Term::Style::Bold); window.fill_style(0, 5, 80, 10, Term::Style::Dim); window.fill_style(0, 10, 80, 15, Term::Style::Underline); // Combine with colors window.set_fg(10, 2, Term::Color(Term::Color::Name::Red)); window.set_style(10, 2, Term::Style::Bold); window.print_str(10, 2, "Bold Red Header"); std::cout << window.render(0, 0, true); std::cout << std::flush; return 0; } ``` -------------------------------- ### Get Cursor Column Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/cursor.md Retrieves the current column index of the cursor. The column index is 1-based. ```cpp std::size_t cursor_col = cursor.column(); ``` -------------------------------- ### Display Program Info with Version Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Shows how to display application information, including the cpp-terminal version and project homepage, in an 'About' dialog. Useful for user information. ```cpp #include "cpp-terminal/version.hpp" #include void show_about() { std::cout << "====================================\n"; std::cout << "MyApplication v1.0\n"; std::cout << "Built with cpp-terminal " << Term::Version::string() << "\n"; std::cout << "Project: " << Term::homepage() << "\n"; std::cout << "====================================\n"; } int main() { show_about(); return 0; } ``` -------------------------------- ### Get Cursor Row Position Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/cursor.md Retrieves the current row index of the cursor. The row index is 1-based. ```cpp std::cout << "Cursor at row " << cursor.row(); ``` -------------------------------- ### Get Global Terminal Instance Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/terminal.md Access the global singleton reference to the terminal instance for configuration and control. ```cpp extern Term::Terminal& terminal; ``` -------------------------------- ### Basic Text Formatting with Styles Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/style.md Demonstrates how to apply various basic text styles like bold, underline, italic, strikethrough, and dim using `Term::style` and reset sequences. Ensure to reset styles after applying them to avoid unintended formatting. ```cpp #include "cpp-terminal/style.hpp" #include int main() { // Bold text std::cout << Term::style(Term::Style::Bold) << "Bold text" << Term::style(Term::Style::ResetBold) << "\n"; // Underlined text std::cout << Term::style(Term::Style::Underline) << "Underlined" << Term::style(Term::Style::ResetUnderline) << "\n"; // Italic text std::cout << Term::style(Term::Style::Italic) << "Italic" << Term::style(Term::Style::ResetItalic) << "\n"; // Strikethrough std::cout << Term::style(Term::Style::Crossed) << "Strikethrough" << Term::style(Term::Style::ResetCrossed) << "\n"; // Dim text std::cout << Term::style(Term::Style::Dim) << "Dim/faint" << Term::style(Term::Style::ResetDim) << "\n"; // Reset all std::cout << Term::style(Term::Style::Reset) << "Back to default\n"; return 0; } ``` -------------------------------- ### Get Screen Width Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/screen.md Retrieves the width of the terminal screen. The returned Column count is convertible to std::size_t. ```cpp const Columns& columns() const noexcept ``` -------------------------------- ### Create Options from Initializer List Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Initialize an Options object by providing a list of desired terminal configuration options. ```cpp Term::Options opts({Term::Option::Raw, Term::Option::NoCursor}); ``` -------------------------------- ### Get Screen Height Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/screen.md Retrieves the height of the terminal screen. The returned Row count is convertible to std::size_t. ```cpp const Rows& rows() const noexcept ``` -------------------------------- ### Get Project Homepage URL Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Retrieves the URL for the cpp-terminal project homepage. Useful for displaying project information. ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::cout << "Project: " << Term::homepage() << "\n"; return 0; } ``` -------------------------------- ### Create Options from Variadic Arguments Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Initialize an Options object using a variable number of terminal configuration options passed as arguments. ```cpp Term::Options opts(Term::Option::Raw, Term::Option::ClearScreen, Term::Option::NoCursor); ``` -------------------------------- ### Get Minor Version Number Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Retrieves the minor version number of the cpp-terminal library. Useful for checking compatibility. ```cpp std::cout << "Minor version: " << Term::Version::minor() << "\n"; ``` -------------------------------- ### Create Empty Options Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Instantiate an Options object with default settings, meaning no specific configurations are initially applied. ```cpp Term::Options defaults; ``` -------------------------------- ### Get Major Version Number Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Retrieves the major version number of the cpp-terminal library. Useful for checking compatibility. ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::cout << "Major version: " << Term::Version::major() << "\n"; return 0; } ``` -------------------------------- ### Get Button Event Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/mouse.md Retrieves the Button object associated with the mouse event, containing both the button type and its action. ```cpp Term::Button button = mouse.getButton(); ``` -------------------------------- ### Creating Terminal Options Objects Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/options.md Demonstrates three methods for creating Term::Options objects: using an initializer list, variadic arguments (recommended), or an empty constructor. Options can then be applied to the terminal. ```cpp #include "cpp-terminal/options.hpp" #include "cpp-terminal/terminal.hpp" int main() { // Method 1: Initializer list Term::Options opts1({Term::Option::Raw, Term::Option::NoCursor}); // Method 2: Variadic arguments (recommended) Term::Options opts2(Term::Option::Raw, Term::Option::NoCursor); // Method 3: Empty options Term::Options opts3; // Apply to terminal Term::terminal.setOptions(Term::Option::Raw, Term::Option::NoCursor); return 0; } ``` -------------------------------- ### Create Window Matching Screen Size Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/window.md Initializes a new Window object to match the dimensions of the current terminal screen. ```cpp Term::Screen current = Term::screen_size(); Term::Window window(current); ``` -------------------------------- ### Get Full Version String Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Retrieves the complete version of cpp-terminal as a string in 'Major.Minor.Patch' format. Useful for logging and display. ```cpp #include "cpp-terminal/version.hpp" #include int main() { std::cout << "cpp-terminal version: " << Term::Version::string() << "\n"; return 0; } ``` -------------------------------- ### Get Button Action Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/mouse.md Retrieves the action performed by the mouse button. Use this to determine if the button was pressed, released, or double-clicked. ```cpp if (button.action() == Term::Button::Action::DoubleClicked) { // Double click detected } ``` -------------------------------- ### Get Focus State Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/focus.md Retrieve the current focus state of the terminal. Use this to determine if the window currently has input focus. ```cpp Term::Focus focus = ...; if (focus.type() == Term::Focus::Type::In) { // Window has focus } ``` -------------------------------- ### Exception Constructors Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/exception.md Demonstrates how to create instances of the Exception class with different parameters. ```APIDOC ## Exception(const std::string& message) ### Description Create an exception with a message. ### Parameters #### Path Parameters - **message** (std::string) - Required - Error message ### Request Example ```cpp throw Term::Exception("Terminal initialization failed"); ``` ## Exception(const std::int64_t& code, const std::string& message) ### Description Create an exception with error code and message. ### Parameters #### Path Parameters - **code** (std::int64_t) - Required - Error code (typically platform-specific) - **message** (std::string) - Required - Human-readable error message ### Request Example ```cpp throw Term::Exception(-1, "I/O error: " + std::string(strerror(errno))); ``` ``` -------------------------------- ### Get Copy-Paste Event Data Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/event.md Safely retrieve a pointer to a string if the event is copy-paste data. Returns nullptr otherwise. ```cpp std::string* get_if_copy_paste(); const std::string* get_if_copy_paste() const; ``` -------------------------------- ### Mouse Constructor with Parameters Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/mouse.md Creates a Mouse event with a specified button and position. Use this constructor when you have a specific mouse button action and location to represent. ```cpp Term::Button click(Term::Button::Type::Left, Term::Button::Action::Pressed); Term::Mouse event(click, 10, 20); ``` -------------------------------- ### Get Patch Version Number Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/version.md Retrieves the patch version number of the cpp-terminal library. Useful for checking bug fix compatibility. ```cpp std::cout << "Patch version: " << Term::Version::patch() << "\n"; ``` -------------------------------- ### Key Constructors Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/key.md This section details the various constructors available for the Key class, allowing initialization from default values, existing Key objects, named constants, characters, integer values, and Unicode code points. ```APIDOC ## Key Constructors ### Key() #### Description Create a NoKey (empty) key. #### Example ```cpp Term::Key no_key; ``` --- ### Key(const Term::Key& key) #### Description Copy constructor. --- ### Key(const Term::Key::Value& v) #### Description Construct from a named key constant. #### Parameters * **v** (`Term::Key::Value`) - Required - Named key constant #### Example ```cpp Term::Key enter_key(Term::Key::Enter); Term::Key escape_key(Term::Key::Esc); ``` --- ### Key(char val) #### Description Construct from a character. #### Parameters * **val** (`char`) - Required - ASCII character #### Example ```cpp Term::Key a_key('a'); Term::Key digit('5'); ``` --- ### Key(std::int32_t val) #### Description Construct from a 32-bit integer value. #### Parameters * **val** (`std::int32_t`) - Required - Key value (ASCII, extended, special) --- ### Key(std::size_t val) #### Description Construct from size_t. --- ### Key(char32_t val) #### Description Construct from Unicode code point. #### Parameters * **val** (`char32_t`) - Required - Unicode code point #### Example ```cpp Term::Key unicode_char(U'é'); ``` --- ``` -------------------------------- ### Get Mouse Event Data Source: https://github.com/jupyter-xeus/cpp-terminal/blob/master/_autodocs/api-reference/event.md Safely retrieve a pointer to Mouse data if the event is a mouse event. Returns nullptr otherwise. ```cpp Mouse* get_if_mouse(); const Mouse* get_if_mouse() const; ```