Debian Codegraph @

Source/DSPSpy/ConsoleHelper.h

raw symbols SCIP
1 // Copyright 2009 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <iostream>
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #define CON_BLACK 0
12 #define CON_RED 1
13 #define CON_GREEN 2
14 #define CON_YELLOW 3
15 #define CON_BLUE 4
16 #define CON_MAGENTA 5
17 #define CON_CYAN 6
18 #define CON_WHITE 7
19 #define CON_BRIGHT 8
20 #define CON_BRIGHT_BLACK CON_BLACK | CON_BRIGHT
21 #define CON_BRIGHT_RED CON_RED | CON_BRIGHT
22 #define CON_BRIGHT_GREEN CON_GREEN | CON_BRIGHT
23 #define CON_BRIGHT_YELLOW CON_YELLOW | CON_BRIGHT
24 #define CON_BRIGHT_BLUE CON_BLUE | CON_BRIGHT
25 #define CON_BRIGHT_MAGENTA CON_MAGENTA | CON_BRIGHT
26 #define CON_BRIGHT_CYAN CON_CYAN | CON_BRIGHT
27 #define CON_BRIGHT_WHITE CON_WHITE | CON_BRIGHT
28
29 inline void CON_Printf(const int x, const int y, const char* fmt, ...)
30 {
31 char tmpbuf[255];
32
33 va_list marker;
34 va_start(marker, fmt);
35 vsprintf(tmpbuf, fmt, marker);
36 va_end(marker);
37
38 printf("\x1b[%d;%dH%s", y, x, tmpbuf);
39 }
40
41 inline void CON_SetColor(u8 foreground, u8 background = CON_BLACK)
42 {
43 u8 bright = foreground & CON_BRIGHT ? 1 : 0;
44
45 if (bright)
46 foreground &= ~CON_BRIGHT;
47
48 printf("\x1b[%d;%d;%dm", 30 + foreground, bright, 40 + background);
49 }
50
51 inline void CON_Clear()
52 {
53 // Escape code to clear the whole screen.
54 printf("\x1b[2J");
55 }
56
57 // libogc's clear escape codes are crappy
58 inline void CON_BlankRow(const int y)
59 {
60 int columns = 0, rows = 0;
61 CON_GetMetrics(&columns, &rows);
62 char blank[columns];
63 std::fill_n(blank, columns, ' ');
64 blank[columns - 1] = '\0';
65 CON_Printf(0, y, "%s", blank);
66 }
67
68 #define CON_PrintRow(x, y, ...) \
69 { \
70 CON_BlankRow(y); \
71 CON_Printf(x, y, __VA_ARGS__); \
72 }