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

multitoolplusplus / app / 14951491935

11 May 2025 02:37AM UTC coverage: 16.901% (-12.5%) from 29.353%
14951491935

push

github

benja2998
code: add calculator shell, move get_char() to char.hpp

10 of 164 new or added lines in 3 files covered. (6.1%)

2 existing lines in 1 file now uncovered.

60 of 355 relevant lines covered (16.9%)

0.18 hits per line

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

28.0
/src/main.cpp
1
/*
2
    * multitool++
3
    * main.cpp
4
*/
5
#include <iostream>
6
#include <string>
7
#include <cstdlib>
8
#include <thread>
9
#include "discord.hpp"
10
#include "telegram.hpp"
11
#include "console.hpp"
12
#include "char.hpp"
13
#include "calculator_shell.hpp"
14

15
#ifdef _WIN32
16
    #include <windows.h>
17
    #include <conio.h>
18
#elif defined(__linux__)
19
    #include <unistd.h>
20
    #include <termios.h>
21
#endif
22

23
/* DOCUMENTATION
24
    * exit(0) - EXIT SUCCESS
25
    * exit(1) - EXIT FAILURE
26
    * exit(10) - UNSUPPORTED OPERATING SYSTEM
27
    * std::cout << string; - CHARACTER OUTPUT
28
    * std::getline(...) - READ LINE FROM USER
29
    * std::stoi(string) - CONVERT STRING TO INTEGER
30
    * system(...) - RUN A SYSTEM COMMAND
31
    * console::clear() - CLEAR THE CONSOLE
32
    * discord::send_webhook(...) - SEND MESSAGE TO DISCORD WEBHOOK
33
    * telegram::send_message(...) - SEND MESSAGE TO TELEGRAM BOT
34
    * ansi::[...] - ANSI ESCAPE CODES FOR COLORING
35
    * If you're reading this section, you may want to make a pull request to expand it
36
*/
37

38
std::string checked1 = "[x]";
39
std::string checked2 = "[ ]";
40
std::string checked3 = "[ ]";
41
std::string checked4 = "[ ]";
42
std::string checked5 = "[ ]";
43
std::string checked6 = "[ ]";
44

45
void initialize();
46

47
void banner() {
1✔
48
    const char* banner = R"(
1✔
49
              .__   __  .__  __                .__                           
50
  _____  __ __|  |_/  |_|__|/  |_  ____   ____ |  |      .__         .__     )";
51

52
    const char* banner2 = R"(
1✔
53
 /     \|  |  \  |\   __\  \   __\/  _ \ /  _ \|  |    __|  |___   __|  |___ 
54
|  Y Y  \  |  /  |_|  | |  ||  | (  <_> |  <_> )  |__ /__    __/  /__    __/ )";
55

56
    const char* banner3 = R"(
1✔
57
|__|_|  /____/|____/__| |__||__|  \____/ \____/|____/    |__|        |__|    
58
      \/                                                                     )";
59
    
60
    std::cout << ansi::BG_BLACK;
1✔
61
    std::cout << ansi::BOLD << ansi::WHITE << banner << ansi::RESET;
1✔
62
    std::cout << ansi::BG_BLACK;
1✔
63
    std::cout << ansi::BOLD << ansi::CYAN << banner2 << ansi::RESET;
1✔
64
    std::cout << ansi::BG_BLACK;
1✔
65
    std::cout << ansi::BOLD << ansi::BLUE << banner3 << ansi::RESET << "\n" <<  "\n";
1✔
66
}
1✔
67

68
void option_exit() {
1✔
69
    std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
1✔
70
    exit(0);
1✔
71
}
72

73
void option_timer() {
×
74
    std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
×
75
    std::cout << ansi::CYAN << "Enter a number of seconds: " << ansi::RESET;
×
76
    std::string seconds;
×
77
    std::getline(std::cin, seconds);
×
78
    int seconds_int;
79
    try {
80
        seconds_int = std::stoi(seconds);
×
81
    }
82
    catch (std::invalid_argument& e) {
×
83
        std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
×
84
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
85
        initialize();
×
86
    }
×
87
    catch (std::out_of_range& e) {
×
88
        std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
×
89
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
90
        initialize();
×
91
    }
×
92
    int timer = seconds_int;
×
93
    while (timer > 0) {
×
94
        std::cout << ansi::WHITE << timer << ansi::RESET << "\n";
×
95
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
96
        timer--;
×
97
    }
98
    initialize();
×
99
}
×
100

101
void option_discord() {
×
102
    std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
×
103
    std::cout << ansi::CYAN << "Enter Discord webhook URL: " << ansi::RESET;
×
104
    std::string webhook_url;
×
105
    std::getline(std::cin, webhook_url);
×
106
            
107
    std::cout << ansi::CYAN << "Enter message to send: " << ansi::RESET;
×
108
    std::string message;
×
109
    std::getline(std::cin, message);
×
110
            
111
    discord::send_webhook(webhook_url, message);
×
112
    initialize();
×
113
}
×
114

115
void option_telegram() {
×
116
    std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
×
117
    std::cout << ansi::CYAN << "Enter Telegram bot token: " << ansi::RESET;
×
118
    std::string bot_token;
×
119
    std::getline(std::cin, bot_token);
×
120

121
    std::cout << ansi::CYAN << "Enter Telegram chat ID: " << ansi::RESET;
×
122
    std::string chat_id;
×
123
    std::getline(std::cin, chat_id);
×
124

125
    std::cout << ansi::CYAN << "Enter message to send: " << ansi::RESET;
×
126
    std::string message;
×
127
    std::getline(std::cin, message);
×
128

129
    telegram::send_message(bot_token, chat_id, message);
×
130
    initialize();
×
131
}
×
132

133
void option_password() {
×
134
    std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
×
135
    std::cout << ansi::CYAN << "Enter password length: " << ansi::RESET;
×
136
    std::string length;
×
137
    std::getline(std::cin, length);
×
138
    int length_int;
139
    try {
140
        length_int = std::stoi(length);
×
141
    }
142
    catch (std::invalid_argument& e) {
×
143
        std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
×
144
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
145
        initialize();
×
146
    }
×
147
    catch (std::out_of_range& e) {
×
148
        std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
×
149
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
150
        initialize();
×
151
    }
×
152
    std::string password = "";
×
153
    for (int i = 0; i < length_int; i++) {
×
154
        const std::string charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;:,.<>?";
×
155
        password += charset[rand() % charset.length()];
×
156
    }
×
157
    std::cout << ansi::GREEN << "Generated password: " << ansi::RESET << password << "\n";
×
158
    std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
×
NEW
159
    char_utils::get_char();
×
160
    initialize();
×
161
}
×
162

163
void menu() {
1✔
164
    console::clear();
1✔
165
    banner();
1✔
166
    std::cout << ansi::BOLD << ansi::ITALIC << ansi::UNDERLINE << ansi::BG_BLUE << ansi::CYAN;
1✔
167
    std::cout << "OPTIONS:                    \n";
1✔
168
    std::cout << ansi::RESET;
1✔
169
    std::cout << ansi::UNDERLINE << ansi::BG_BLUE << ansi::CYAN;
1✔
170
    std::cout << checked1 << " exit                    \n";
1✔
171
    std::cout << checked2 << " timer                   \n";
1✔
172
    std::cout << checked3 << " send Discord message    \n";
1✔
173
    std::cout << checked4 << " send Telegram message   \n"; 
1✔
174
    std::cout << checked5 << " generate secure password\n";
1✔
175
    std::cout << checked6 << " calculator shell        \n";
1✔
176
    std::cout << "\n";
1✔
177
    std::cout << ansi::RESET;
1✔
178
    std::cout << ansi::CYAN << "Use W/S to navigate, E to select.\n" << ansi::RESET;
1✔
179
}
1✔
180

181
void read() {
1✔
182
    char check = char_utils::get_char();
1✔
183
    //std::cout << ansi::CYAN << "Validating choice... " << ansi::RESET;
184

185
    if (check == 'w' || check == 'W') {
1✔
186
        if (checked2 == "[x]") {
×
187
            checked2 = "[ ]";
×
188
            checked1 = "[x]";
×
189
        }
190
        else if (checked3 == "[x]") {
×
191
            checked3 = "[ ]";
×
192
            checked2 = "[x]";
×
193
        }
194
        else if (checked4 == "[x]") {
×
195
            checked4 = "[ ]";
×
196
            checked3 = "[x]";
×
197
        }
198
        else if (checked5 == "[x]") {
×
199
            checked5 = "[ ]";
×
200
            checked4 = "[x]";
×
201
        }
NEW
202
        else if (checked6 == "[x]") {
×
NEW
203
            checked6 = "[ ]";
×
NEW
204
            checked5 = "[x]";
×
205
        }
UNCOV
206
        initialize();
×
207
    }
208
    else if (check == 's' || check == 'S') {
1✔
209
        if (checked1 == "[x]") {
×
210
            checked1 = "[ ]";
×
211
            checked2 = "[x]";
×
212
        }
213
        else if (checked2 == "[x]") {
×
214
            checked2 = "[ ]";
×
215
            checked3 = "[x]";
×
216
        }
217
        else if (checked3 == "[x]") {
×
218
            checked3 = "[ ]";
×
219
            checked4 = "[x]";
×
220
        }
221
        else if (checked4 == "[x]") {
×
222
            checked4 = "[ ]";
×
223
            checked5 = "[x]";
×
224
        }
NEW
225
        else if (checked5 == "[x]") {
×
NEW
226
            checked5 = "[ ]";
×
NEW
227
            checked6 = "[x]";
×
228
        }
UNCOV
229
        initialize();
×
230
    }
231
    else if (check == 'e' || check == 'E') {
1✔
232
        if (checked1 == "[x]") {
1✔
233
            option_exit();
1✔
234
        }
235
        else if (checked2 == "[x]") {
×
236
            option_timer();
×
237
        }
238
        else if (checked3 == "[x]") {
×
239
            option_discord();
×
240
        }
241
        else if (checked4 == "[x]") {
×
242
            option_telegram();
×
243
        }
244
        else if (checked5 == "[x]") {
×
245
            option_password();
×
246
        }
NEW
247
        else if (checked6 == "[x]") {
×
NEW
248
            std::cout << ansi::GREEN << "Valid choice!" << ansi::RESET << "\n";
×
NEW
249
            std::cout << ansi::BOLD << ansi::ITALIC << ansi::CYAN << "Welcome to the calculator shell, type 'help' for commands.\n" << ansi::RESET;
×
NEW
250
            option_shell();
×
251
        }
252
    }
253
    else {
254
        std::cout << ansi::RED << "Invalid choice." << ansi::RESET << "\n";
×
255
        std::this_thread::sleep_for(std::chrono::seconds(1));
×
256
        initialize();
×
257
    }
258
}
×
259

260
void initialize() {
1✔
261
    console::clear();
1✔
262
    menu();
1✔
263
    read();
1✔
264
}
×
265

266
void checkCurlIsInstalled() {
1✔
267
#ifdef _WIN32
268
    int curl = system("curl --version >nul 2>&1");
269
    if (curl != 0) {
270
        std::cout << "Curl not installed. Install it by running: winget install cURL.cURL\n";
271
        exit(1);
272
    }
273
#elif defined(__linux__)
274
    int curl = system("curl --version >/dev/null 2>&1");
1✔
275
    if (curl != 0) {
1✔
276
        std::cout << "Curl not installed. Install it by running: sudo <your package manager> install curl\n";
×
277
        exit(1);
×
278
    }
279
#else
280
    std::cout << "Unsupported OS. Please make sure you have modified the source code before compiling for another OS.";
281
    exit(10);
282
#endif
283
}
1✔
284

285
int main() {
1✔
286
    checkCurlIsInstalled();
1✔
287
    initialize();
1✔
288
}
×
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

© 2025 Coveralls, Inc