Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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
/csiPublic

Easily generate ANSI escape sequence strings to print colored or stylized text, move the cursor, or erase parts of the display.

License

NotificationsYou must be signed in to change notification settings

WesOfX/csi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

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.

How to print text with style:

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;}

How to print text with color:

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;}

How to move the cursor:

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;}

How to erase the display:

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;}

About

Easily generate ANSI escape sequence strings to print colored or stylized text, move the cursor, or erase parts of the display.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp