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
/*
4
This program is free software: you can redistribute it and/or modify it under the
5
terms of the GNU Lesser General Public License as published by the Free Software
6
Foundation, either version 3 of the License, or (at your option) any later version.
7
8
This program is distributed in the hope that it will be useful, but WITHOUT ANY
9
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
11
12
You should have received a copy of the GNU Lesser General Public License along with this
13
program. If not, see <https://www.gnu.org/licenses/>.
14
*/
15
16
#include "
format.h
"
17
18
using namespace
std;
19
20
const
string
textClear
=
"\x1b[2J"
;
21
const
string
textReset
=
"\x1b[0m"
;
22
23
const
string
textBold
=
"\x1b[1m"
;
24
const
string
textItalic
=
"\x1b[3m"
;
25
const
string
textUnderline
=
"\x1b[4m"
;
26
const
string
textStrikethrough
=
"\x1b[9m"
;
27
28
const
string
textDefault
=
"\x1b[39m"
;
29
const
string
textBlack
=
"\x1b[30m"
;
30
const
string
textRed
=
"\x1b[31m"
;
31
const
string
textGreen
=
"\x1b[32m"
;
32
const
string
textYellow
=
"\x1b[33m"
;
33
const
string
textBlue
=
"\x1b[34m"
;
34
const
string
textMagenta
=
"\x1b[35m"
;
35
const
string
textCyan
=
"\x1b[36m"
;
36
const
string
textWhite
=
"\x1b[37m"
;
37
38
const
string
bgDefault
=
"\x1b[49m"
;
39
const
string
bgBlack
=
"\x1b[40m"
;
40
const
string
bgRed
=
"\x1b[41m"
;
41
const
string
bgGreen
=
"\x1b[42m"
;
42
const
string
bgYellow
=
"\x1b[43m"
;
43
const
string
bgBlue
=
"\x1b[44m"
;
44
const
string
bgMagenta
=
"\x1b[45m"
;
45
const
string
bgCyan
=
"\x1b[46m"
;
46
const
string
bgWhite
=
"\x1b[47m"
;
47
48
const
int
sleepShort
= 100;
49
const
int
sleepMedium
= 500;
50
const
int
sleepLong
= 1000;
51
52
void
time::sleep
(
int
dur) {
53
std::this_thread::sleep_for(std::chrono::milliseconds(dur));
54
}
55
56
string
setCursorPosition
(
int
offsetY,
int
offsetX) {
57
string
base =
"\x1b["
;
58
base = base + to_string(offsetY) +
";"
+ to_string(offsetX) +
"H"
;
59
return
base;
60
}
61
62
void
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
}
time::sleep
static void sleep(int dur)
Definition
format.cpp:52
textItalic
const string textItalic
Definition
format.cpp:24
bgMagenta
const string bgMagenta
Definition
format.cpp:44
textDefault
const string textDefault
Definition
format.cpp:28
textGreen
const string textGreen
Definition
format.cpp:31
bgRed
const string bgRed
Definition
format.cpp:40
sleepShort
const int sleepShort
Definition
format.cpp:48
textWhite
const string textWhite
Definition
format.cpp:36
sleepMedium
const int sleepMedium
Definition
format.cpp:49
textRed
const string textRed
Definition
format.cpp:30
fetchConsoleDimensions
void fetchConsoleDimensions(int &row, int &col)
Definition
format.cpp:62
bgCyan
const string bgCyan
Definition
format.cpp:45
bgDefault
const string bgDefault
Definition
format.cpp:38
textReset
const string textReset
Definition
format.cpp:21
textCyan
const string textCyan
Definition
format.cpp:35
textMagenta
const string textMagenta
Definition
format.cpp:34
bgWhite
const string bgWhite
Definition
format.cpp:46
setCursorPosition
string setCursorPosition(int offsetY, int offsetX)
Definition
format.cpp:56
textStrikethrough
const string textStrikethrough
Definition
format.cpp:26
textUnderline
const string textUnderline
Definition
format.cpp:25
textClear
const string textClear
Definition
format.cpp:20
bgGreen
const string bgGreen
Definition
format.cpp:41
sleepLong
const int sleepLong
Definition
format.cpp:50
textBlue
const string textBlue
Definition
format.cpp:33
bgBlue
const string bgBlue
Definition
format.cpp:43
bgBlack
const string bgBlack
Definition
format.cpp:39
bgYellow
const string bgYellow
Definition
format.cpp:42
textYellow
const string textYellow
Definition
format.cpp:32
textBlack
const string textBlack
Definition
format.cpp:29
textBold
const string textBold
Definition
format.cpp:23
format.h
Header file for the ANSI Escape code related functions.
mode
mode
hiding mean/sd/uplim/lowlim/event_id columns in the table
Definition
main.cpp:104
src
format.cpp
Generated on Sun Dec 1 2024 17:52:09 for Stock Market Simulator by
1.12.0