• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eric15342335 / comp2113-engg1340-group-project / #45

17 Jun 2024 02:39PM UTC coverage: 73.913% (+0.4%) from 73.553%
#45

push

travis-ci

web-flow
Fix cmake exe unicode bug (#145)

Makefile and main.cpp was unrelated changes.

1462 of 1978 relevant lines covered (73.91%)

721.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.07
/src/draw.cpp
1
/// @file draw.cpp
2
/// Functions that handles the drawing and display of various elements
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
#include "draw.h"
16

17
#include "file_io.h"
18

19
void drawLogo(int row, int col) {
7✔
20
    const int wordWidth = 73; // Width of the longest word
7✔
21
    const int wordHeight = 8; // Height for each word
7✔
22
    std::vector<std::string> logo = parseLogo();
7✔
23

24
    std::cout << textClear << setCursorPosition(0, 0);
7✔
25

26
    // Will not print logo if terminal cannot fit
27
    if (row > wordHeight && col > wordWidth) {
7✔
28
        // Will use fileIO for this
29
        for (int i = 0; i < 9; i++) {
70✔
30
            std::cout << logo[i] << "\n";
63✔
31
        }
32
        time::sleep(sleepMedium);
7✔
33
        std::cout << textClear << setCursorPosition(0, 0);
7✔
34
        time::sleep(sleepShort);
7✔
35
        for (int i = 9; i < 18; i++) {
70✔
36
            std::cout << logo[i] << "\n";
63✔
37
        }
38
        time::sleep(sleepMedium);
7✔
39
        std::cout << textClear << setCursorPosition(0, 0);
7✔
40
        time::sleep(sleepShort);
7✔
41
        for (int i = 18; i < 27; i++) {
70✔
42
            std::cout << logo[i] << "\n";
63✔
43
        }
44
        time::sleep(sleepMedium);
7✔
45
    }
7✔
46
    else {
47
        std::cout << "Welcome to Stock Market Simulator!\n";
×
48
    }
49
    std::cout << textClear << setCursorPosition(0, 0);
7✔
50
}
7✔
51

52
void drawRoundInfo(
60✔
53
    int row, int col, int round, float balance, std::string player, float indexHSI) {
54
    std::ignore = row; // Shutup compiler
60✔
55
    std::cout << setCursorPosition(2, 5);
60✔
56
    std::cout << "Round " << round;
60✔
57

58
    if (player.size() > 15) {
60✔
59
        std::cout << setCursorPosition(4, 0);
×
60
        std::cout << player.erase(12) << "...";
×
61
    }
62
    else {
63
        std::cout << setCursorPosition(
60✔
64
            4, static_cast<int>((15 - player.size()) / 2 + 1));
60✔
65
        std::cout << player;
60✔
66
    }
67
    std::cout << setCursorPosition(2, col - 10);
60✔
68
    std::cout << "$" << balance;
60✔
69
    std::cout << setCursorPosition(4, col - 12);
60✔
70
    std::cout << "  HSI: " << indexHSI;
60✔
71
}
60✔
72

73
void drawEventBar(int row, int col) {
60✔
74
    std::ignore = row; // Shutup compiler
60✔
75
    int width = col - 32;
60✔
76

77
    std::cout << setCursorPosition(2, 16) << "\u250C";
60✔
78
    for (int i = 0; i < width - 1; i++) {
4,080✔
79
        std::cout << "\u2500";
4,020✔
80
    }
81
    std::cout << "\u2510" << setCursorPosition(3, 16) << "\u2502";
60✔
82
    std::cout << setCursorPosition(3, width + 16) << "\u2502";
60✔
83
    std::cout << setCursorPosition(4, 16) << "\u2514";
60✔
84
    for (int i = 0; i < width - 1; i++) {
4,080✔
85
        std::cout << "\u2500";
4,020✔
86
    }
87
    std::cout << "\u2518";
60✔
88
}
60✔
89

90
void listEvents(int row, int col, std::vector<Stock_event> events) {
1✔
91
    int height;
92
    int width = col - 20;
1✔
93

94
    if (static_cast<int>(events.size()) < row - 10) {
1✔
95
        if (static_cast<int>(events.size()) != 0) {
1✔
96
            height = static_cast<int>(events.size()) + 2;
1✔
97
        }
98
        else {
99
            height = 3;
×
100
        }
101
    }
102
    else {
103
        height = row - 10;
×
104
    }
105

106
    std::cout << setCursorPosition(6, 10) << "\u250C";
1✔
107
    for (int i = 0; i < width - 1; i++) {
80✔
108
        std::cout << "\u2500";
79✔
109
    }
110
    std::cout << "\u2510";
1✔
111
    for (int i = 0; i < height; i++) {
6✔
112
        std::cout << setCursorPosition(i + 7, 10);
5✔
113
        std::cout << "\u2502";
5✔
114
        std::cout << setCursorPosition(i + 7, width + 10);
5✔
115
        std::cout << "\u2502";
5✔
116
    }
117
    std::cout << setCursorPosition(height + 7, 10) << "\u2514";
1✔
118
    for (int i = 0; i < width - 1; i++) {
80✔
119
        std::cout << "\u2500";
79✔
120
    }
121
    std::cout << "\u2518";
1✔
122

123
    std::cout << setCursorPosition(7, 11);
1✔
124
    for (int i = 0; i < width - 1; i++) {
80✔
125
        std::cout << " ";
79✔
126
    }
127
    if (static_cast<int>(events.size()) == 0) {
1✔
128
        std::cout << setCursorPosition(8, 11);
×
129
        std::cout << "There are currently no events!";
×
130
        for (int i = 0; i < width - 31; i++) {
×
131
            std::cout << " ";
×
132
        }
133
        std::cout << setCursorPosition(9, 11);
×
134
        for (int i = 0; i < width - 1; i++) {
×
135
            std::cout << " ";
×
136
        }
137
    }
138
    else {
139
        for (int i = 1; i < static_cast<int>(events.size()) + 1; i++) {
4✔
140
            std::cout << setCursorPosition(i + 7, 11);
3✔
141
            std::cout << i << ". " << events[i - 1].text;
3✔
142
            int digits = (((i) / 10) + 1);
3✔
143
            for (int j = 0;
3✔
144
                 j < width - static_cast<int>(events[i - 1].text.size()) - 3 - digits;
3✔
145
                 j++) {
146
                std::cout << " ";
×
147
            }
148
        }
149
        std::cout << setCursorPosition(static_cast<int>(events.size()) + 8, 11);
1✔
150
        for (int i = 0; i < width - 1; i++) {
80✔
151
            std::cout << " ";
79✔
152
        }
153
    }
154
}
1✔
155

156
void drawButton(int row, int col) {
60✔
157
    int width;
158
    int buttons;
159

160
    std::vector<std::string> options = {"[B] Buy", "[S] Sell", "[T] Toggle View",
161
        "[E] Events", "[N] Next Round", "[X] Exit"}; // Add stuff here
540✔
162

163
    buttons = options.size();
60✔
164
    width = (col / buttons);
60✔
165

166
    std::cout << textReset << setCursorPosition(row - 1, 3);
60✔
167
    for (int i = 0; i < buttons; i++) {
420✔
168
        i % 2 == 0 ? std::cout << bgWhite << textBlack
360✔
169
                   : std::cout << bgBlack << textWhite;
180✔
170
        for (int j = 0; j < static_cast<int>((width - options[i].length()) / 2); j++) {
1,320✔
171
            std::cout << " ";
960✔
172
        }
173
        std::cout << textBold << options[i] << "\x1b[22m";
360✔
174
        for (int j = 0; j < static_cast<int>((width - options[i].length() -
1,440✔
175
                                              (width - options[i].length()) / 2));
1,440✔
176
             j++) {
177
            std::cout << " ";
1,080✔
178
        }
179
    }
180
    std::cout << textReset << "\n";
60✔
181
}
60✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc