Rishka
RISC-V virtual runtime in C/C++ made for ESP32-WROVER
io.h
Go to the documentation of this file.
1/*
2 * This file is part of the Rishka distribution (https://github.com/nthnn/rishka).
3 * Copyright (c) 2024 Nathanne Isip.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
27#ifndef LIBRISHKA_IO_H
28#define LIBRISHKA_IO_H
29
30#include <librishka/types.h>
31
37#define TERM_FG_BLACK F("\e[30m")
39#define TERM_FG_RED F("\e[31m")
41#define TERM_FG_GREEN F("\e[32m")
43#define TERM_FG_YELLOW F("\e[33m")
45#define TERM_FG_BLUE F("\e[34m")
47#define TERM_FG_MAGENTA F("\e[35m")
49#define TERM_FG_CYAN F("\e[36m")
51#define TERM_FG_WHITE F("\e[37m")
53#define TERM_FG_HBLACK F("\e[90m")
55#define TERM_FG_HRED F("\e[91m")
57#define TERM_FG_HGREEN F("\e[92m")
59#define TERM_FG_HYELLOW F("\e[93m")
61#define TERM_FG_HBLUE F("\e[94m")
63#define TERM_FG_HMAGENTA F("\e[95m")
65#define TERM_FG_HCYAN F("\e[96m")
67#define TERM_FG_HWHITE F("\e[97m")
75#define TERM_BG_BLACK F("\e[40m")
77#define TERM_BG_RED F("\e[41m")
79#define TERM_BG_GREEN F("\e[42m")
81#define TERM_BG_YELLOW F("\e[43m")
83#define TERM_BG_BLUE F("\e[44m")
85#define TERM_BG_MAGENTA F("\e[45m")
87#define TERM_BG_CYAN F("\e[46m")
89#define TERM_BG_WHITE F("\e[47m")
91#define TERM_BG_HBLACK F("\e[100m")
93#define TERM_BG_HRED F("\e[101m")
95#define TERM_BG_HGREEN F("\e[102m")
97#define TERM_BG_HYELLOW F("\e[103m")
99#define TERM_BG_HBLUE F("\e[104m")
101#define TERM_BG_HMAGENTA F("\e[105m")
103#define TERM_BG_HCYAN F("\e[106m")
105#define TERM_BG_HWHITE F("\e[107m")
113#define TERM_STYLE_NORMAL F("\e[0m")
115#define TERM_STYLE_BOLD F("\e[1m")
117#define TERM_STYLE_ITALIC F("\e[3m")
119#define TERM_STYLE_UNDERLINED F("\e[4m")
121#define TERM_STYLE_BLINK F("\e[5m")
123#define TERM_STYLE_INVERSE F("\e[7m")
134class IO final {
135public:
143 static void print(const string text);
144
157 static void print(
158 const string text,
159 const string fg,
160 const string bg = TERM_BG_BLACK,
161 const string style = TERM_STYLE_NORMAL
162 );
163
172 static void println(const string text);
173
181 static void print(i64 number);
182
191 static void println(i64 number);
192
200 static void print(u64 number);
201
210 static void println(u64 number);
211
220 static void print(double number);
221
230 static void println(double number);
231
238 static void println();
239
256 static bool printf(string format, ...);
257
265 static i32 available();
266
274 static i32 peek();
275
285 static bool find(string target, usize size);
286
297 static bool find_until(string target, string terminator);
298
306 static void set_timeout(u64 timeout);
307
315 static u64 get_timeout();
316
324 static rune readch();
325
333 static string readline();
334};
335
336#endif /* LIBRISHKA_IO_H */
Class for handling input/output operations in Rishka applications.
Definition: io.h:134
static i32 available()
Check if there is data available to read from the input stream.
Definition: librishka_io.cpp:134
static bool find(string target, usize size)
Search for a target string in the input stream.
Definition: librishka_io.cpp:142
static void println()
Prints a new line to the output stream.
Definition: librishka_io.cpp:74
static bool find_until(string target, string terminator)
Search for a target string in the input stream until a terminator is encountered.
Definition: librishka_io.cpp:146
static bool printf(string format,...)
Prints formatted output.
Definition: librishka_io.cpp:78
static string readline()
Read a line of text from the input stream.
Definition: librishka_io.cpp:130
static u64 get_timeout()
Get the current timeout for input operations.
Definition: librishka_io.cpp:154
static i32 peek()
Peek at the next character in the input stream.
Definition: librishka_io.cpp:138
static rune readch()
Read a Unicode character from the input stream.
Definition: librishka_io.cpp:126
static void set_timeout(u64 timeout)
Set the timeout for input operations.
Definition: librishka_io.cpp:150
static void print(const string text)
Print text to the output stream.
Definition: librishka_io.cpp:22
#define TERM_STYLE_NORMAL
Normal text style.
Definition: io.h:113
#define TERM_BG_BLACK
Black background color.
Definition: io.h:75
Header file for common data types used in Rishka applications.
signed int i32
Alias for the signed 32-bit integer type.
Definition: types.h:58
char rune
Alias for the Unicode character type.
Definition: types.h:34
signed long int i64
Alias for the signed 64-bit integer type.
Definition: types.h:64
unsigned long int u64
Alias for the unsigned 64-bit integer type.
Definition: types.h:88
u32 usize
Alias for the unsigned integer type representing size.
Definition: types.h:94