Skip to content

Repository files navigation

cpptui

still under heavy development

description

A minimal library for creating TUI applications. Uses macro magic (not intentionally, but it's needed to reduce code size and overcome some of c++ 's difficulties).

features

  • minimal
  • zero dependencies
  • cross-platform (mostly?)
  • c++11
  • low-level
  • performance: TODO

  • colors
  • styles
  • raw mode
  • alternate screen
  • performant screen size query
  • custom function for resize handling, NOTE: you should probably lock stdout, stdin when you use this feature, also, doesn't work on Windows

input

a pretty handy header with functions and types to improve reading input from stdin.

supported input:

  • basic symbols, such as ['~', ';', '*', ...], but not ['$', '€', ...]
  • Ctrl+alphabetical characters
  • arrows
  • touchpad/mouse scroll
  • Backspace, (Shift)Tab, Enter/Return, Delete, Page[Up,Down], Home,End, Insert,
  • F[1,2,3,4]NOTE: the other F-keys are damn hard to implement, might be done in the future though
  • basic characters, be it upper or lowercase
  • NOTE: special ones like: ['ö', 'ä', 'á', ...] are safely ignored

coordinates

coords.hpp provides easy management of coordinates

usage

you could use poac:

poac new my-tui-app
cd my-tui-app
poac add "csboo/cpptui"

see examples, but basically just

#include"tui.hpp"
#include<utility>// for std::pairusingnamespacetui::input;intmain() {
tui::init(false); // alternate buffer, raw mode, no cursorauto screen_size = tui::screen::size(); // initially setconst tui::string msg = "Hello Bello, TUI!"; // stylable extension of `std::string`const tui::string note = "press q or Ctrl+C to quit";
Input input; // this will handle special stuff like arrows, ctrl+c, ...while (input != SpecKey::CtrlC && input != 'q') { // main loop// NOTE: use `.size()` before styling, as it'd be completely crazy after applying styles// `msg` will be in the middle of the screentui::cursor::set_position(screen_size.first / 2 - 1, screen_size.second / 2 - (msg.size() / 2));
std::cout << msg.blue().link("https://github.com/csboo/cpptui").bold().underline();
// `msg` will be in the middle of the screentui::cursor::set_position(screen_size.first / 2 + 1, screen_size.second / 2 - (note.size() / 2));
std::cout << note.on_rgb(106, 150, 137).rgb(148, 105, 117).italic().dim();
std::cout.flush();
input = Input::read(); // read into an `Input`
}
tui::reset(); // restore to where we came fromreturn0;
}

why

non-goals

  • full mouse support
  • huge number of widgets
  • high level functions
  • thousands of more features: just what's necessary

kinda alternatives

About

tui lib c++ :D

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages