Write a Minimal Main Function
Before introducing buffers and animations, let’s start with the smallest useful program. In this step you will initialize the terminal, print a few colored lines, flush the output, and restore the screen state before exiting.
This example shows how simple terminal output can already produce readable and structured results.
Create and open the source file:
$ nano signal-board/src/main.cpp
Add the following code:
<project>/signal-board/src/main.cpp#include <erbsland/cterm/Terminal.hpp> using namespace erbsland::cterm; auto main() -> int { auto terminal = Terminal{Size{80, 25}}; terminal.initializeScreen(); terminal.printLine( bg::Blue, fg::BrightWhite, " Signal Board ", Color::reset(), " ", fg::BrightBlack, "Direct output with readable color arguments."); terminal.writeLineBreak(); terminal.printLine(fg::BrightGreen, "Status", fg::BrightBlack, ": online"); terminal.printLine(fg::BrightCyan, "Mode", fg::BrightBlack, ": tutorial step 1"); terminal.setDefaultColor(); terminal.flush(); terminal.restoreScreen(); return 0; }
What This Example Shows
Even this minimal program already demonstrates several useful parts of the API:
Terminalhandles screen initialization and restoration.printLine()accepts text, full colors, foreground colors, and background colors in a single call.fg::...andbg::...provide a compact and readable way to apply colors.Color::reset()resets the colors in the middle of a line.
For small tools, status messages, or diagnostic output, this direct printing style is often all you need.