• Stars
    star
    447
  • Rank 97,700 (Top 2 %)
  • Language
    C++
  • License
    Other
  • Created about 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ library for writing multiplatform terminal applications

CPP-Terminal logo

Linux CI Windows CI MacOS CI docs CodeQL pre-commit pre-commit.ci status

CPP-Terminal is a small and dependency-free C++ library for writing platform independent terminal-based applications. It follows the "Zero-overhead principle" and limits externally included files to the C++ STL. Being cross-platform we are currently supporting Windows, Linux and MacOS and are providing an unified API across all platforms. Our main features are consisting of Colors, Keyboard input, terminal resize handling, as well as other common terminal functionality. It's also possible to open a managed terminal from a windows GUI application.

Hello World example

To write a simple Hello World program, all you need to do is:

#include "cpp-terminal/terminal.hpp"
#include <iostream>

int main()
{
  std::cout << "Just including terminal.hpp activate \033[31mcolor\033[0m !" << std::endl;
}

or

#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 !"<<color_fg(Term::Color::Name::Default)<< std::endl;
}

On windows you can simply create or attach a console through a GUI application by doing:

#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 !"<<color_fg(Term::Color::Name::Default)<< std::endl;
  return 0;
}

Until 2021, CPP-Terminal used to be a single header library. Now, CPP-Terminal consists out of multiple small and usage oriented headers:

  • cpp-terminal/input.hpp: functions for gathering input
  • cpp-terminal/prompt.hpp: some variations of different prompts
  • cpp-terminal/window.hpp: a fully managed terminal window for terminal user interfaces (TUI)
  • cpp-terminal/version.hpp: macros with cpp-terminal's version number

CPP-Terminal tries to be a small and simple replacement for ncurses. This approach keeps the code small and maintainable, but also easy to extend it's functionality. We limit ourselves to a subset of features that work on all supported platforms without needing to worry about style differences or other changes. Any application written with CPP-Terminal will work everywhere out of the box natively, without emulation or extra work. The small codebase makes CPP-Terminal easy to debug and extend, as well as understanding what happens behind the scenes in the library's core.

Examples

We have created serval examples to show possible use cases of CPP-Terminal and to get you started more quickly. Every example works natively on all platforms in the exact same way:

  • colors.cpp: basic color, style and unicode demo
  • kilo.cpp: the kilo text editor ported to C++ and CPP-Terminal instead of using Linux specific API
  • menu.cpp: An interactive menu using only the contents of cpp-terminal/base.hpp
  • menu_window.cpp: An interactive menu using the fully managed windowing system from cpp-terminal/window.hpp
  • keys.cpp: Interactively shows the keys pressed

Supported platforms

Platform Supported versions Arch Compiler C++ standard
Windows 10 and higher* x86, x86_64 MSVC 2019, MSVC 2022, clang11, clang12, clang13, clang14, clang15, clang-cl 11,14,17,20
(Windows) MSYS2 All supported x86, x86_64 ucrt , clang, mingw 11,14,17,20
MacOS 11 xcode11.7 xcode12.4 xcode12.5.1 xcode13 gcc10 gcc11 gcc12 11,14,17,20
MacOS 12 xcode13.1 xcode13.2 xcode13.3 xcode13.4 11,14,17,20
Linux All supported x86_64 4.7<=GCC<= 12 3.5<=Clang<=15 intel-oneapi 11,14,17,20
Linux (dockcross) All supported arm64 armv5 armv5-musl armv5-uclibc armv6 armv7a, mips, mipsel-lts, s390x, ppc64le, xtensa-uclibc, x86, x64, x64-clang, x64-tinycc 4.7<=GCC<= 12 3.5<=Clang<=15 11,14,17,20

Windows versions prior Windows 10 are missing the Win32 API functionality for entering the "raw mode" and therefore won't work. They are also lacking ANSI support. See #173 for adding support to prior windows versions for MSVC / Win32.

How to use

Adding CPP-Terminal to your own project is really easy. We have collected various ways with easy how-to's in our documentation.

Documentation

Contributing

Contributing to CPP-Terminal is highly appreciated and can be done in more ways than code. Extending it's functionality, reporting or fixing bugs and extending the documentations are just a few of them.

License

CPP-Terminal is licensed under the terms of the MIT License by OndΕ™ej ČertΓ­k.

Projects using cpp-terminal

Similar Projects

Colors

Libraries to handle color output.

C++:

Drawing

JavaScript:

Prompt

Libraries to handle a prompt in terminals.

C and C++:

Python:

General TUI libraries

C and C++:

Python:

Go:

Rust:

JavaScript:

More Repositories

1

xeus-cling

Jupyter kernel for the C++ programming language
C++
2,682
star
2

xeus

Implementation of the Jupyter kernel protocol in C++
C++
838
star
3

xeus-python

Jupyter kernel for the Python programming language
C++
431
star
4

xeus-sqlite

Jupyter kernel for SQLite
C++
156
star
5

xeus-sql

Jupyter kernel for SQL databases
C++
148
star
6

xwidgets

C++ backend for Jupyter interactive widgets
C++
131
star
7

xleaflet

C++ backend for the jupyter leaflet widget
C++
77
star
8

xeus-octave

Jupyter kernel for GNU Octave
Jupyter Notebook
57
star
9

xeus-lua

Jupyter kernel for the Lua programming language
C++
40
star
10

xproperty

Traitlets-like C++ properties and implementation of the observer pattern
C++
36
star
11

xeus-robot

Jupyter kernel for Robot Framework
Jupyter Notebook
30
star
12

xeus-calc

Jupyter kernel for a simple calculator
C++
17
star
13

xeus-python-wheel

Building a PyPI wheel for xeus-python
CMake
12
star
14

xena

The world needs Xena, stay tuned!
CMake
8
star
15

xeus-nelson

Jupyter kernel for Nelson
C++
7
star
16

xeus-cookiecutter

Cookiecutter for xeus-based Jupyter kernels
CMake
5
star
17

xhale

Converter from sphinx and breathe inventory files to doxygen tag files
Python
5
star
18

xeus-qt

ZeroMQ-based middleware for xeus integrated in the Qt event loop
CMake
5
star
19

xeus-wren

Jupyter kernel for the Wren programming language
C++
5
star
20

xeus-zmq

ZeroMQ-based middleware for xeus
C++
5
star
21

xcanvas

C++ back-end for ipycanvas
C++
5
star
22

robotframework-interpreter

Utilities for building a Robot Framework interpreter
Python
3
star
23

xvega-bindings

xvega bindings for xeus
C++
3
star
24

xeus-lite

Emscripten-based middleware for xeus
C++
2
star
25

xeus-python-shell

Core Python code for xeus-python
Python
2
star