Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
ansi.c File Reference

Implemented following https://en.wikipedia.org/wiki/ANSI_escape_code. More...

#include "ansi.h"

Go to the source code of this file.

Functions

rgb buildRgb ()
 Builds a rgb struct.
ansiRgbColor buildAnsiRgbColor ()
 Builds a ANSI rgb color struct.
ansiStandardColor buildAnsiStandardColor ()
 Builds a ANSI standard color struct.
color buildColor ()
 Builds a color struct.
graphicRendition buildGraphicRendition ()
 Builds a graphic rendition struct.
void clearScreen ()
 Clears the entire terminal's window's content.
void setForegroundColor (color color)
 Sets the terminal's foreground color.
void setBackgroundColor (color color)
 Sets the terminal's background color.
void setColor (color color)
 Sets both terminal's foreground color and background color, if specified.
void printGraphicRendition (char *text, graphicRendition rendition)
 Prints a text with the graphic rendition specified with the struct. Standard C format specifiers are not handled.
void printgr (const char *text)
 Prints a text with the graphic rendition specified with custom graphic rendition format specifiers.
void printfgr (char *text,...)
 Prints text as printgr but handles standard C format specifiers %, d, i, u, x, X, f, F, s, n. Integers are always interpreted in base 10.
char getChar ()
 Gets the char pressed on the keyboard without waiting for 'Enter' to be pressed.
void Pause (bool clear)
 Waits for the user to press a key without waiting for 'Enter' to be pressed.
void screenSize (int *width, int *height)
 It returns the width and the height of the screen. On unix-like platforms, in case of errors, it sets them to -1.
void cursorUp (int n)
 Moves the cursor up by n rows.
void cursorDown (int n)
 Moves the cursor down by n rows.
void cursorForward (int n)
 Moves the cursor to the right by n columns.
void cursorBack (int n)
 Moves the cursor to the left by n columns.
void cursorNextLine (int n)
 Moves the cursor at the beginning of the line n rows down.
void cursorPreviousLine (int n)
 Moves the cursor at the beginning of the line n rows up.
void cursorHorizontalAbsolute (int n)
 Moves the cursor to column n.
void cursorPosition (int n, int m)
 Moves the cursor at n-th row and at the m-th column.
void eraseInDisplay (int n)
 Clears part of the screen.
void eraseInLine (int n)
 Erases part of the line.
void scrollUp (int n)
 Scrolls the whole page up by n rows.
void scrollDown (int n)
 Scrolls the whole page down by n rows.
void deviceStatusReport (int *row, int *col)
 Gets the cursor position.
void graphicReset ()
 Resets the graphic rendition.
void bold ()
 Toggles bold text.
void italic ()
 Toggles italic text.
void underlined ()
 Toggles singled underlined text.
void slowBlinking ()
 Toggles slow blinking.
void doublyUnderlined ()
 Toggles doubly underlined text.
void setStandardForegroundColor (ansiStandardColors foregroundColor)
 Sets the ANSI standard foreground color.
void setRGBForegroundColor (rgb rgbColor)
 Sets the RGB foreground color.
void defaultForegroundColor ()
 Resets the foreground color.
void setStandardBackgroundColor (ansiStandardColors backgroundColor)
 Sets the ANSI standard background color.
void setRGBBackgroundColor (rgb rgbColor)
 Sets the RGB background color.
void defaultBackgroundColor ()
 Resets the background color.

Detailed Description

Implemented following https://en.wikipedia.org/wiki/ANSI_escape_code.

Function's names are as much as possible consistent with the quoted document.

NOTICE: not every function declared in this header is part of ANSI standard.

NOTICE: for these structures are available some builders function that you should use if you want to build structures with unset properties.

Definition in file ansi.c.

Function Documentation

◆ bold()

void bold ( )

Toggles bold text.

Definition at line 451 of file ansi.c.

◆ buildAnsiRgbColor()

ansiRgbColor buildAnsiRgbColor ( )

Builds a ANSI rgb color struct.

Returns
Returns a ANSI rgb color struct with properties set to NONE.

Definition at line 41 of file ansi.c.

◆ buildAnsiStandardColor()

ansiStandardColor buildAnsiStandardColor ( )

Builds a ANSI standard color struct.

Returns
Returns a ANSI standard color struct with properties set to NONE.

Definition at line 50 of file ansi.c.

◆ buildColor()

color buildColor ( )

Builds a color struct.

Returns
Returns a color struct with properties set to NONE. isRgbColor property is set to false.

Definition at line 59 of file ansi.c.

◆ buildGraphicRendition()

graphicRendition buildGraphicRendition ( )

Builds a graphic rendition struct.

Returns
Returns a graphic rendition struct with properties set to NONE. bold and italic properties are set to false.

Definition at line 70 of file ansi.c.

◆ buildRgb()

rgb buildRgb ( )

Builds a rgb struct.

Returns
Returns a rgb struct with properties set to 0.

Definition at line 31 of file ansi.c.

◆ clearScreen()

void clearScreen ( )

Clears the entire terminal's window's content.

Definition at line 85 of file ansi.c.

◆ cursorBack()

void cursorBack ( int n)

Moves the cursor to the left by n columns.

Parameters
nThe columns to go backward.

Definition at line 361 of file ansi.c.

◆ cursorDown()

void cursorDown ( int n)

Moves the cursor down by n rows.

Parameters
nThe rows to go down.

Definition at line 347 of file ansi.c.

◆ cursorForward()

void cursorForward ( int n)

Moves the cursor to the right by n columns.

Parameters
nThe columns to go forward.

Definition at line 354 of file ansi.c.

◆ cursorHorizontalAbsolute()

void cursorHorizontalAbsolute ( int n)

Moves the cursor to column n.

Parameters
nThe column to go to.

Definition at line 382 of file ansi.c.

◆ cursorNextLine()

void cursorNextLine ( int n)

Moves the cursor at the beginning of the line n rows down.

Parameters
nThe rows to go down.

Definition at line 368 of file ansi.c.

◆ cursorPosition()

void cursorPosition ( int n,
int m )

Moves the cursor at n-th row and at the m-th column.

Parameters
nThe row to go to.
mThe column to go to.

Definition at line 389 of file ansi.c.

◆ cursorPreviousLine()

void cursorPreviousLine ( int n)

Moves the cursor at the beginning of the line n rows up.

Parameters
nThe rows to go up.

Definition at line 375 of file ansi.c.

◆ cursorUp()

void cursorUp ( int n)

Moves the cursor up by n rows.

Parameters
nThe rows to go up.

Definition at line 340 of file ansi.c.

◆ defaultBackgroundColor()

void defaultBackgroundColor ( )

Resets the background color.

Definition at line 491 of file ansi.c.

◆ defaultForegroundColor()

void defaultForegroundColor ( )

Resets the foreground color.

Definition at line 479 of file ansi.c.

◆ deviceStatusReport()

void deviceStatusReport ( int * row,
int * col )

Gets the cursor position.

Parameters
rowThe row of the cursor.
colThe column of the cursor.

Definition at line 426 of file ansi.c.

◆ doublyUnderlined()

void doublyUnderlined ( )

Toggles doubly underlined text.

Definition at line 467 of file ansi.c.

◆ eraseInDisplay()

void eraseInDisplay ( int n)

Clears part of the screen.

Parameters
nIf n is set to 0, it clears from the cursor to the end of the screen. If n is set to 1, it clears from the cursor to the beginning of the screen. If n is set to 2, it clears the entire screen (on MS-DOS moves the cursor to the upper left corner). If n is set to 3, it clears the screen and erases the scrollback buffer.

Definition at line 398 of file ansi.c.

◆ eraseInLine()

void eraseInLine ( int n)

Erases part of the line.

Parameters
nIf n is set to 0, it clears from the cursor to the end of the line. If n is set to 1, it clears from the cursor to the beginning of the line. If n is set to 2, it clears the entire line. In any case the cursor position is unchanged.

Definition at line 405 of file ansi.c.

◆ getChar()

char getChar ( )

Gets the char pressed on the keyboard without waiting for 'Enter' to be pressed.

Returns
The pressed char on the keyboard.

Definition at line 281 of file ansi.c.

◆ graphicReset()

void graphicReset ( )

Resets the graphic rendition.

Definition at line 447 of file ansi.c.

◆ italic()

void italic ( )

Toggles italic text.

Definition at line 455 of file ansi.c.

◆ Pause()

void Pause ( bool clear)

Waits for the user to press a key without waiting for 'Enter' to be pressed.

Parameters
clearFlag for determining if the screen has to be cleaned, if set to true.

Definition at line 305 of file ansi.c.

◆ printfgr()

void printfgr ( char * text,
... )

Prints text as printgr but handles standard C format specifiers %, d, i, u, x, X, f, F, s, n. Integers are always interpreted in base 10.

Parameters
textThe text with custom graphic rendition format specifiers and standard C format specifiers.
ValuesValues to be concatenated.

Definition at line 222 of file ansi.c.

◆ printgr()

void printgr ( const char * text)

Prints a text with the graphic rendition specified with custom graphic rendition format specifiers.

Custom graphic rendition format specifiers: #b# for bold text, #i# for italic text, #u# for underlined text, #du# for doubly underlined text, #n# for setting ANSI standard color represented by n, #bl# for slow blinking, #r# for graphic reset.

For setting RGB colors use #fg;r;g;b# or #bg;r;g;b# where fg or bg represents if the color has to be applied to the foreground or to the background and r, g, b are the values for r, g, b components of the color representation and must be between 0 and 255;

If the passed format does not comply with this specification, then the passed format text is going to be printed except for the #s.

If printing # is needed, use ##.

Standard C formats specifiers are not handled.

Parameters
textThe text with custom graphic rendition format specifiers to be printed.

Definition at line 127 of file ansi.c.

◆ printGraphicRendition()

void printGraphicRendition ( char * text,
graphicRendition rendition )

Prints a text with the graphic rendition specified with the struct. Standard C format specifiers are not handled.

Parameters
textThe text to be printed.
renditionThe graphic rendition for the text.

Definition at line 111 of file ansi.c.

◆ screenSize()

void screenSize ( int * width,
int * height )

It returns the width and the height of the screen. On unix-like platforms, in case of errors, it sets them to -1.

Parameters
widthThe width, as the number of columns, for the terminal window.
heightThe height, as the number of row, for the terminal window.

Definition at line 312 of file ansi.c.

◆ scrollDown()

void scrollDown ( int n)

Scrolls the whole page down by n rows.

Parameters
nThe number of the rows to scroll down.

Definition at line 419 of file ansi.c.

◆ scrollUp()

void scrollUp ( int n)

Scrolls the whole page up by n rows.

Parameters
nThe number of the rows to scroll up.

Definition at line 412 of file ansi.c.

◆ setBackgroundColor()

void setBackgroundColor ( color color)

Sets the terminal's background color.

Parameters
colorThe background color to be set.

Definition at line 99 of file ansi.c.

◆ setColor()

void setColor ( color color)

Sets both terminal's foreground color and background color, if specified.

Parameters
colorThe colors to be set.

Definition at line 106 of file ansi.c.

◆ setForegroundColor()

void setForegroundColor ( color color)

Sets the terminal's foreground color.

Parameters
colorThe foreground color to be set.

Definition at line 92 of file ansi.c.

◆ setRGBBackgroundColor()

void setRGBBackgroundColor ( rgb rgbColor)

Sets the RGB background color.

Parameters
rgbColorThe RGB background color to be set.

Definition at line 487 of file ansi.c.

◆ setRGBForegroundColor()

void setRGBForegroundColor ( rgb rgbColor)

Sets the RGB foreground color.

Parameters
rgbColorThe RGB foreground color to be set.

Definition at line 475 of file ansi.c.

◆ setStandardBackgroundColor()

void setStandardBackgroundColor ( ansiStandardColors backgroundColor)

Sets the ANSI standard background color.

Parameters
backgroundColorThe ANSI standard background color to be set.

Definition at line 483 of file ansi.c.

◆ setStandardForegroundColor()

void setStandardForegroundColor ( ansiStandardColors foregroundColor)

Sets the ANSI standard foreground color.

Parameters
foregroundColorThe ANSI standard foreground color to be set.

Definition at line 471 of file ansi.c.

◆ slowBlinking()

void slowBlinking ( )

Toggles slow blinking.

Definition at line 463 of file ansi.c.

◆ underlined()

void underlined ( )

Toggles singled underlined text.

Definition at line 459 of file ansi.c.