Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A cross-platform C++ library for simple terminal utilities, including screen clearing, cursor movement, colorful text output, and terminal size retrieval.

License

Notifications You must be signed in to change notification settings

Bahaaio/TerminalPlusPlus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

59 Commits

Repository files navigation

Terminal++

A lightweight, cross-platform C++ library for creating rich terminal applications with color support, cursor manipulation, and asynchronous operations. Works seamlessly on Windows and UNIX-like systems.

Table of contents

Installation

Include the header file in your project:

#include "Terminal.hpp"

Compile with:

g++ -std=c++17 your_file.c++ -o your_program

No special setup or configuration is required.

Basic usage

Basic printing operations:

printer.println("Hello, Terminal++!");

Chain multiple operations:

printer.setTextColor(Color::Blue)
 .setBackgroundColor(Color::White)
 .println("Styled text!");

Text styling

Available text styles through the TextStyle class:

  • TextStyle::Normal - Default text style
  • TextStyle::Bold - Bold weight text
  • TextStyle::Dim - Dimmed text intensity
  • TextStyle::Italic - Italic text
  • TextStyle::Underline - Underlined text
  • TextStyle::Blink - Blinking text
  • TextStyle::Reverse - Reversed foreground/background colors
  • TextStyle::Hidden - Hidden text
  • TextStyle::Strike - Strikethrough text

Text styles Reference

Colors

Basic colors

Available through the Color class:

  • Color::Black
  • Color::Red
  • Color::Green
  • Color::Yellow
  • Color::Blue
  • Color::Magenta
  • Color::Cyan
  • Color::White
  • Color::Reset - Resets both text and background colors to terminal defaults

8-bit colors

Use any color from 0 to 255:

printer.setTextColor(42) // Text color
 .setBackgroundColor(200); // Background color

8-bit Color Reference Chart

RGB colors

printer.setTextColor(Color::Rgb(94, 60, 108)) // purple color
 .println("Termina++ in purple!");

Terminal operations

Screen control

Clear operations available through ClearType enum:

  • ClearType::All - Clear screen and history
  • ClearType::Purge - Clear visible screen only
  • ClearType::Line - Clear current line

Example:

Terminal::clearScreen(ClearType::All);

Cursor control

Move cursor

Cursor::moveTo(10, 5);

Coordinates start at [1, 1] in the top-left corner of the terminal.

Hide cursor

Cursor::hideCursor();

Show cursor

Cursor::showCursor();

Cursor styles

  • Cursor::Default - the default cursor shape used by the user
  • Cursor::BlinkingBlock - a blinking block
  • Cursor::SteadyBlock - a non blinking block
  • Cursor::BlinkingUnderline - a blinking underline _
  • Cursor::SteadyUnderline - a non blinking underline
  • Cursor::BlinkingBar - a blinking bar |
  • Cursor::SteadyBar - a non blinking bar

Change cursor style

Example:

Cursor::setStyle(Cursor::BlinkingUnderline);

Terminal information

Get size

auto [width, height] = Terminal::size();

Check resize

if (term.isResized()) {/*Handle resize*/}

Get new dimensions

int newWidth, newHeight;
term.isResized(newWidth, newHeight);

Window title

Terminal::setTitle("My Terminal App");

Sleep operation

Terminal::sleep(1000); // Sleep for 1 second

Terminal reset

Terminal::reset();

Resets all the terminal's attributes

Input handling

Supported keyboard buttons

  • Backspace: keyCode::Backspace
  • Enter: keyCode::Enter
  • Escape: keyCode::Esc
  • Tab: keyCode::Tab
  • Space: keyCode::Space
  • ArrowKeys

Input methods

Read single character

char c = Input::getChar();

Gets a character from unbuffered input.

Read a string

std::string str = Input::getString("Enter text: ");

Read a line

std::string line = Input::getLine("Enter a line: ");

Check key press

if (Terminal::keyPressed()) {/*Handle key press*/}

Asynchronous operations

Run background task:

term.nonBlock([]() {
 printer.println("Processing...")
 .setTextColor(Color::Green)
 .println("Task complete!");
 Terminal::sleep(1000);
});

Wait for completion [optional]:

term.awaitCompletion();

All background threads are automatically joined when the Terminal instance is destroyed.

Reference charts

Text styles

8-bit color chart

Examples

For complete working examples - see the examples directory

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

About

A cross-platform C++ library for simple terminal utilities, including screen clearing, cursor movement, colorful text output, and terminal size retrieval.

Resources

License

Stars

Watchers

Forks

AltStyle によって変換されたページ (->オリジナル) /