CPP-Terminal

repository·master·Indexed 20 days ago

https://github.com/jupyter-xeus/cpp-terminal

A lightweight, dependency-free C++ library for building cross-platform terminal applications and TUIs. It provides a unified API for colors, keyboard input, and window management across Windows 10+, Linux, and MacOS, serving as a maintainable alternative to ncurses.

Tokens
775
Snippets
2
Records
5
Agent score
22%

What's inside cpp-terminal

  1. Overview of CPP-Terminal

    master
    CPP-Terminal is a dependency-free, cross-platform C++ library designed for writing platform-independent terminal-based applications. It follows the 'Zero-overhead principle' and relies only on the C++ STL. It provides a unified API for Windows, Linux, and MacOS, covering features like colors, keyboard input, and terminal resize handling. It is intended as a lightweight, maintainable alternative to ncurses.
  2. Understand the CPP-Terminal header structure

    master

    CPP-Terminal is organized into several small, usage-oriented headers rather than a single monolithic file:

    • cpp-terminal/input.hpp: Functions for gathering keyboard input.
    • cpp-terminal/prompt.hpp: Various prompt implementations.
    • cpp-terminal/window.hpp: A fully managed terminal window system for Terminal User Interfaces (TUI).
    • cpp-terminal/version.hpp: Macros containing the library version number.
    • cpp-terminal/terminal.hpp: Core terminal functionality.
    • cpp-terminal/color.hpp: Color and styling utilities.
  3. Create a managed console from a Windows GUI application

    master

    On Windows, you can create or attach a console from a GUI application by using a WinMain entry point and including windows.h.

    #include "cpp-terminal/terminal.hpp"
    #include "cpp-terminal/color.hpp"
    #include <iostream>
    #include <windows.h>
    
    int __stdcall WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show)
    {
      std::cout << Term::color_fg(Term::Color::Name::Red) << "Hello world !" << Term::color_fg(Term::Color::Name::Default) << std::endl;
      return 0;
    }
  4. Use CPP-Terminal for colored output

    master

    You can use CPP-Terminal to add color to your terminal output. You can either use raw ANSI escape codes (which terminal.hpp helps activate) or use the provided Term::color_fg API with Term::Color::Name.

    #include "cpp-terminal/terminal.hpp"
    #include "cpp-terminal/color.hpp"
    #include <iostream>
    
    int main()
    {
      std::cout << Term::color_fg(Term::Color::Name::Red) << "Hello world !" << Term::color_fg(Term::Color::Name::Default) << std::endl;
    }
  5. Supported platforms and requirements

    master

    CPP-Terminal supports the following platforms and C++ standards:

    PlatformSupported VersionsArchCompilerC++ Standard
    Windows10+x86, x86_64MSVC 2019/2022, clang11, 14, 17, 20
    Windows (MSYS2)Allx86, x86_64ucrt, clang, mingw11, 14, 17, 20
    MacOS11, 12-xcode, gcc11, 14, 17, 20
    LinuxAllx86_64GCC 4.7+, Clang 3.5+11, 14, 17, 20

    Note: Windows versions prior to Windows 10 are not supported because they lack the Win32 API functionality for 'raw mode' and ANSI support.