Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
ansi.h
Go to the documentation of this file.
1// Copyright (C) 2025 Giulio Salvi, Jacopo Paradisi
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
26
27#include "vector.h"
28#include "utility.h"
29
30#ifndef _ANSI_H_
32 #define _ANSI_H_
33
35 #define NUMBER_DECIMALS_DIGITS 6
36
38 typedef uint8_t underline;
40 typedef uint8_t ansiStandardColors;
41
43 typedef struct rgb {
45 uint8_t r;
47 uint8_t g;
49 uint8_t b;
50 } rgb;
51
59
67
75
77 typedef struct color {
83
95
96
99 rgb buildRgb();
112
114 void clearScreen();
123 void setColor(color color);
127 void printGraphicRendition(char* text, graphicRendition rendition);
140 void printgr(const char* text);
144 void printfgr(char* text, ...);
147 char getChar();
150 void Pause(bool clear);
154 void screenSize(int* width, int* height);
155
158 void cursorUp(int n);
161 void cursorDown(int n);
164 void cursorForward(int n);
167 void cursorBack(int n);
170 void cursorNextLine(int n);
173 void cursorPreviousLine(int n);
176 void cursorHorizontalAbsolute(int n);
180 void cursorPosition(int n, int m);
183 void eraseInDisplay(int n);
186 void eraseInLine(int n);
189 void scrollUp(int n);
192 void scrollDown(int n);
196 void deviceStatusReport(int* row, int* col);
197
199 void graphicReset();
201 void bold();
203 void italic();
205 void underlined();
207 void slowBlinking();
209 void doublyUnderlined();
215 void setRGBForegroundColor(rgb rgbColor);
223 void setRGBBackgroundColor(rgb rgbColor);
226#endif
void underlined()
Toggles singled underlined text.
Definition ansi.c:459
rgb buildRgb()
Builds a rgb struct.
Definition ansi.c:31
void Pause(bool clear)
Waits for the user to press a key without waiting for 'Enter' to be pressed.
Definition ansi.c:305
void cursorDown(int n)
Moves the cursor down by n rows.
Definition ansi.c:347
void printgr(const char *text)
Prints a text with the graphic rendition specified with custom graphic rendition format specifiers.
Definition ansi.c:127
void setColor(color color)
Sets both terminal's foreground color and background color, if specified.
Definition ansi.c:106
void eraseInDisplay(int n)
Clears part of the screen.
Definition ansi.c:398
void setForegroundColor(color color)
Sets the terminal's foreground color.
Definition ansi.c:92
void setRGBBackgroundColor(rgb rgbColor)
Sets the RGB background color.
Definition ansi.c:487
void deviceStatusReport(int *row, int *col)
Gets the cursor position.
Definition ansi.c:426
void printGraphicRendition(char *text, graphicRendition rendition)
Prints a text with the graphic rendition specified with the struct. Standard C format specifiers are ...
Definition ansi.c:111
void defaultBackgroundColor()
Resets the background color.
Definition ansi.c:491
void eraseInLine(int n)
Erases part of the line.
Definition ansi.c:405
void graphicReset()
Resets the graphic rendition.
Definition ansi.c:447
void bold()
Toggles bold text.
Definition ansi.c:451
ansiStandardColor buildAnsiStandardColor()
Builds a ANSI standard color struct.
Definition ansi.c:50
ansiRgbColor buildAnsiRgbColor()
Builds a ANSI rgb color struct.
Definition ansi.c:41
void defaultForegroundColor()
Resets the foreground color.
Definition ansi.c:479
void cursorUp(int n)
Moves the cursor up by n rows.
Definition ansi.c:340
void scrollDown(int n)
Scrolls the whole page down by n rows.
Definition ansi.c:419
uint8_t underline
Defines the type underlined as unsigned integer 1 byte large.
Definition ansi.h:38
void doublyUnderlined()
Toggles doubly underlined text.
Definition ansi.c:467
void cursorHorizontalAbsolute(int n)
Moves the cursor to column n.
Definition ansi.c:382
void cursorPosition(int n, int m)
Moves the cursor at n-th row and at the m-th column.
Definition ansi.c:389
void screenSize(int *width, int *height)
It returns the width and the height of the screen. On unix-like platforms, in case of errors,...
Definition ansi.c:312
char getChar()
Gets the char pressed on the keyboard without waiting for 'Enter' to be pressed.
Definition ansi.c:281
void setRGBForegroundColor(rgb rgbColor)
Sets the RGB foreground color.
Definition ansi.c:475
void clearScreen()
Clears the entire terminal's window's content.
Definition ansi.c:85
graphicRendition buildGraphicRendition()
Builds a graphic rendition struct.
Definition ansi.c:70
void cursorBack(int n)
Moves the cursor to the left by n columns.
Definition ansi.c:361
void italic()
Toggles italic text.
Definition ansi.c:455
void setBackgroundColor(color color)
Sets the terminal's background color.
Definition ansi.c:99
void cursorPreviousLine(int n)
Moves the cursor at the beginning of the line n rows up.
Definition ansi.c:375
void setStandardForegroundColor(ansiStandardColors foregroundColor)
Sets the ANSI standard foreground color.
Definition ansi.c:471
void scrollUp(int n)
Scrolls the whole page up by n rows.
Definition ansi.c:412
void setStandardBackgroundColor(ansiStandardColors backgroundColor)
Sets the ANSI standard background color.
Definition ansi.c:483
void slowBlinking()
Toggles slow blinking.
Definition ansi.c:463
color buildColor()
Builds a color struct.
Definition ansi.c:59
void printfgr(char *text,...)
Prints text as printgr but handles standard C format specifiers %, d, i, u, x, X, f,...
Definition ansi.c:222
uint8_t ansiStandardColors
Defines the type ansiStandardColors as unsigned integer 1 byte large.
Definition ansi.h:40
void cursorNextLine(int n)
Moves the cursor at the beginning of the line n rows down.
Definition ansi.c:368
void cursorForward(int n)
Moves the cursor to the right by n columns.
Definition ansi.c:354
Defines a basic structure for RGB foreground color and background color for a piece of printable text...
Definition ansi.h:61
rgb bgRgb
Background RGB color field.
Definition ansi.h:65
rgb fgRgb
Foreground RGB color field.
Definition ansi.h:63
Defines a basic structure for standard ANSI foreground color and background color for a piece of prin...
Definition ansi.h:53
ansiStandardColors fgColor
Foreground ANSI standard color field.
Definition ansi.h:55
ansiStandardColors bgColor
Background ANSI standard color field.
Definition ansi.h:57
Defines a struct for representing a generic color.
Definition ansi.h:77
__color color
Color field.
Definition ansi.h:81
bool isRgbColor
Boolean flag for determining if the color field is an ansiRgbColor or an ansiStandardColor.
Definition ansi.h:79
Defines a struct for graphic rendition including properties for bold, italic, underlined and colored ...
Definition ansi.h:85
bool bold
Boolean flag to determine if the text has to be bold.
Definition ansi.h:87
color color
The color for the text and the its background.
Definition ansi.h:93
underline underlined
Flag to determine if the text has to be underlined, singly or doubly.
Definition ansi.h:91
bool italic
Boolean flag to determine if the text has to be italic.
Definition ansi.h:89
Defines a basic structure for RGB colors.
Definition ansi.h:43
uint8_t g
Green component field.
Definition ansi.h:47
uint8_t b
Blue component field.
Definition ansi.h:49
uint8_t r
Red component field.
Definition ansi.h:45
Defines a union between RGB colors and standard ANSI colors (should not be used externally)
Definition ansi.h:69
ansiRgbColor rgbColor
RGB color field.
Definition ansi.h:71
ansiStandardColor stdColor
ANSI standard color field.
Definition ansi.h:73
Definition of utility functions.
Definition of vector structure and related functions.