Coder Social home page Coder Social logo

mumbi / cpp-terminal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jupyter-xeus/cpp-terminal

0.0 0.0 0.0 1.01 MB

C++ library for writing multiplatform terminal applications

Home Page: https://jupyter-xeus.github.io/cpp-terminal/

License: Other

Shell 0.18% C++ 84.27% PowerShell 0.04% CMake 15.51%

cpp-terminal's Introduction

CPP-Terminal logo

Linux CI Windows CI MacOS CI 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 crossplatform 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/io.hpp"

#include <iostream>

int main()
{
  std::cout << "\033[31mHello world !\033[0m" << std::endl;
  return 0;
}

or

#include "cpp-terminal/io.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;
  return 0;
}

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

#include "cpp-terminal/io.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/base.hpp: everything for basic Terminal control
  • 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

The library uses private header for platform dependent code:

  • cpp-terminal/private/conversion.hpp: Various conversions
  • cpp-terminal/private/platform.hpp: platform dependent code

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 docs

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:

cpp-terminal's People

Contributors

flagarde avatar mcwertgaming avatar certik avatar pre-commit-ci[bot] avatar dependabot[bot] avatar wolfv avatar dpoerio avatar martinrenou avatar kinetictheory avatar milo46 avatar tobiaswallner avatar krsch avatar bryancheny avatar btlmd avatar mcourteaux avatar awvwgk avatar guillaumelepape avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.