- Notifications
You must be signed in to change notification settings - Fork2
Easily generate ANSI escape sequence strings to print colored or stylized text, move the cursor, or erase parts of the display.
License
WesOfX/csi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
csi
provides easy to use methods that return special strings for controlling the terminal. For example,enable(style::bold)
anddisable(style::bold)
return"\033[1m"
and"\033[21m"
which the terminal interprets as commands to enable and disable bold.
Theenable
anddisable
methods takestyle
values and return strings that enable or disable a style.style
is anenum class
of 5 styles:bold
,italics
,underline
,strikethrough
, andinverse
.inverse
inverts the text color and the background color as-if the text is highlighted.
#include<iostream>#include"csi.hpp"intmain(){/* Enable bold, print "Hello World!", disable bold, then print a newline.*/std::cout <<csi::enable(csi::style::bold) <<"Hello World!" <<csi::disable(csi::style::bold) << std::endl;}
Theforeground
andbackground
methods takecolor
values and return strings that set the text color or the background color.color
is anenum class
of 9 colors:none
,black
,red
,green
,yellow
,blue
,magenta
,cyan
, andwhite
.none
is the terminal's default color.
#include<iostream>#include"csi.hpp"intmain(){/* Set the text color to yellow, print "Hello World!", set the text color to default, then print a new line*/std::cout <<csi::foreground(csi::color::yellow) <<"Hello World!" <<csi::foreground() << std::endl;/* Set the background color to blue, print "Hello World!", * set the background color to default, then print a new line*/std::cout <<csi::background(csi::color::blue) <<"Hello World!" <<csi::background() << std::endl;}
There are 7 methods for moving the cursor:cursor_up
,cursor_down
,cursor_forward
,cursor_back
,cursor_next_line
,cursor_previous_line
, andcursor_position
.cursor_position
accepts two parameters:row
andcolumn
, both 1 by default (top-left corner) while the other methods accept a single parameter, also 1 by default.
#include<iostream>#include"csi.hpp"intmain(){/* Set the cursor position to the second column of the second row, print "Hello World!", then print a new line.*/std:: cout <<csi::cursor_position(2,2) <<"Hello World!" << std::endl;}
Theerase_display
anderase_line
methods accepterase_mode
values as parameters and return strings which erase lines or even the whole display.erase_mode
is anenum class
which defines three modes:to_end
,to_beginning
, andall
.to_end
erases from the cursor to the end of the line/display.to_beginning
erases from the cursor to the beginning of the line/display.all
erases the entire line/display. For both methods,erase_mode
isall
by default.
#include<iostream>#include"csi.hpp"intmain(){/* Erase the display, set the cursor position to the top-left, print "Hello World!", then print a new line*/std:: cout <<csi::erase_display() <<csi::cursor_position() <<"Hello World!" << std::endl;}