Stock Market Simulator main e8c3612
A game that provides a realistic stock buying experience with unpredictable trends to test investment strategies.
Loading...
Searching...
No Matches
format.cpp
Go to the documentation of this file.
1/// @file format.cpp
2/// ANSI Escape Code related functions.
3/*
4This program is free software: you can redistribute it and/or modify it under the
5terms of the GNU Lesser General Public License as published by the Free Software
6Foundation, either version 3 of the License, or (at your option) any later version.
7
8This program is distributed in the hope that it will be useful, but WITHOUT ANY
9WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
11
12You should have received a copy of the GNU Lesser General Public License along with this
13program. If not, see <https://www.gnu.org/licenses/>.
14*/
15
16#include "format.h"
17
18using namespace std;
19
20const string textClear = "\x1b[2J";
21const string textReset = "\x1b[0m";
22
23const string textBold = "\x1b[1m";
24const string textItalic = "\x1b[3m";
25const string textUnderline = "\x1b[4m";
26const string textStrikethrough = "\x1b[9m";
27
28const string textDefault = "\x1b[39m";
29const string textBlack = "\x1b[30m";
30const string textRed = "\x1b[31m";
31const string textGreen = "\x1b[32m";
32const string textYellow = "\x1b[33m";
33const string textBlue = "\x1b[34m";
34const string textMagenta = "\x1b[35m";
35const string textCyan = "\x1b[36m";
36const string textWhite = "\x1b[37m";
37
38const string bgDefault = "\x1b[49m";
39const string bgBlack = "\x1b[40m";
40const string bgRed = "\x1b[41m";
41const string bgGreen = "\x1b[42m";
42const string bgYellow = "\x1b[43m";
43const string bgBlue = "\x1b[44m";
44const string bgMagenta = "\x1b[45m";
45const string bgCyan = "\x1b[46m";
46const string bgWhite = "\x1b[47m";
47
48const int sleepShort = 100;
49const int sleepMedium = 500;
50const int sleepLong = 1000;
51
52void time::sleep(int dur) {
53 std::this_thread::sleep_for(std::chrono::milliseconds(dur));
54}
55
56string setCursorPosition(int offsetY, int offsetX) {
57 string base = "\x1b[";
58 base = base + to_string(offsetY) + ";" + to_string(offsetX) + "H";
59 return base;
60}
61
62void fetchConsoleDimensions(int & row, int & col) {
63 /** @todo Suggest terminal sizes.
64 * Dynamic size needs testing on windows.
65 * Not implemented because of time constraints.
66 */
67 int mode = 2;
68 // Before moving to production, we use the printTable() function with
69 // the mode parameter set to "dev" for testing purposes.
70 // However, in production, we will use the mode parameter set to "normal"
71 // which will result in fewer columns being printed. This reduction in columns
72 // may cause misalignment of the table, so we need to adjust the offset accordingly.
73 // for dev mode, the offset is 0
74 const int normalTableModeOffset = 20;
75 switch (mode) {
76 case 1:
77 row = 30;
78 col = 80 - normalTableModeOffset;
79 break;
80 case 2:
81 row = 36;
82 col = 120 - normalTableModeOffset;
83 break;
84 case 3:
85 row = 48;
86 col = 160 - normalTableModeOffset;
87 break;
88 default:
89 row = 36;
90 col = 120 - normalTableModeOffset;
91 break;
92 }
93}
static void sleep(int dur)
Definition format.cpp:52
const string textItalic
Definition format.cpp:24
const string bgMagenta
Definition format.cpp:44
const string textDefault
Definition format.cpp:28
const string textGreen
Definition format.cpp:31
const string bgRed
Definition format.cpp:40
const int sleepShort
Definition format.cpp:48
const string textWhite
Definition format.cpp:36
const int sleepMedium
Definition format.cpp:49
const string textRed
Definition format.cpp:30
void fetchConsoleDimensions(int &row, int &col)
Definition format.cpp:62
const string bgCyan
Definition format.cpp:45
const string bgDefault
Definition format.cpp:38
const string textReset
Definition format.cpp:21
const string textCyan
Definition format.cpp:35
const string textMagenta
Definition format.cpp:34
const string bgWhite
Definition format.cpp:46
string setCursorPosition(int offsetY, int offsetX)
Definition format.cpp:56
const string textStrikethrough
Definition format.cpp:26
const string textUnderline
Definition format.cpp:25
const string textClear
Definition format.cpp:20
const string bgGreen
Definition format.cpp:41
const int sleepLong
Definition format.cpp:50
const string textBlue
Definition format.cpp:33
const string bgBlue
Definition format.cpp:43
const string bgBlack
Definition format.cpp:39
const string bgYellow
Definition format.cpp:42
const string textYellow
Definition format.cpp:32
const string textBlack
Definition format.cpp:29
const string textBold
Definition format.cpp:23
Header file for the ANSI Escape code related functions.
mode
hiding mean/sd/uplim/lowlim/event_id columns in the table
Definition main.cpp:104