Skip to content

Commit 5506718

Browse files
committed
chore: convert files to proper formats
1 parent 66119d7 commit 5506718

3 files changed

Lines changed: 216 additions & 216 deletions

File tree

build.bat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@echo off
2-
3-
mkdir build
4-
cd build
5-
cmake ..
6-
cmake --build .
7-
echo Done. The executable is in ./build/Debug directory.
1+
@echo off
2+
3+
mkdir build
4+
cd build
5+
cmake ..
6+
cmake --build .
7+
echo Done. The executable is in ./build/Debug directory.

src/calculator_shell.hpp

Lines changed: 181 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,181 @@
1-
#include <iostream>
2-
#include <string>
3-
#include <thread>
4-
#include "console.hpp"
5-
#include "ansi.hpp"
6-
#include "char.hpp"
7-
8-
#ifndef CALCULATOR_SHELL_HPP
9-
#define CALCULATOR_SHELL_HPP
10-
inline void option_shell() {
11-
std::string command;
12-
std::cout << ansi::CYAN << ">> " << ansi::RESET << ansi::GREEN;
13-
std::getline(std::cin, command);
14-
if (command == "help") {
15-
std::cout << ansi::BOLD << ansi::ITALIC << ansi::CYAN;
16-
std::cout << "Commands:\n";
17-
std::cout << "help - show this help message\n";
18-
std::cout << "exit - exit the shell\n";
19-
std::cout << "clear - clear the screen\n";
20-
std::cout << "sub - substract two numbers\n";
21-
std::cout << "add - add two numbers\n";
22-
std::cout << "mul - multiply two numbers\n";
23-
std::cout << "div - divide two numbers\n";
24-
std::cout << ansi::RESET;
25-
option_shell();
26-
}
27-
else if (command == "exit") {
28-
}
29-
else if (command == "clear") {
30-
console::clear();
31-
option_shell();
32-
}
33-
else if (command == "sub") {
34-
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
35-
std::string num1;
36-
std::getline(std::cin, num1);
37-
int num1_int;
38-
try {
39-
num1_int = std::stoi(num1);
40-
}
41-
catch (std::invalid_argument& e) {
42-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
43-
std::this_thread::sleep_for(std::chrono::seconds(1));
44-
option_shell();
45-
}
46-
catch (std::out_of_range& e) {
47-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
48-
std::this_thread::sleep_for(std::chrono::seconds(1));
49-
option_shell();
50-
}
51-
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
52-
std::string num2;
53-
std::getline(std::cin, num2);
54-
int num2_int;
55-
try {
56-
num2_int = std::stoi(num2);
57-
}
58-
catch (std::invalid_argument& e) {
59-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
60-
}
61-
catch (std::out_of_range& e) {
62-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
63-
}
64-
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int - num2_int << "\n";
65-
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
66-
char_utils::get_char();
67-
option_shell();
68-
}
69-
else if (command == "add") {
70-
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
71-
std::string num1;
72-
std::getline(std::cin, num1);
73-
int num1_int;
74-
try {
75-
num1_int = std::stoi(num1);
76-
}
77-
catch (std::invalid_argument& e) {
78-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
79-
std::this_thread::sleep_for(std::chrono::seconds(1));
80-
option_shell();
81-
}
82-
catch (std::out_of_range& e) {
83-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
84-
std::this_thread::sleep_for(std::chrono::seconds(1));
85-
option_shell();
86-
}
87-
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
88-
std::string num2;
89-
std::getline(std::cin, num2);
90-
int num2_int;
91-
try {
92-
num2_int = std::stoi(num2);
93-
}
94-
catch (std::invalid_argument& e) {
95-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
96-
}
97-
catch (std::out_of_range& e) {
98-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
99-
}
100-
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int + num2_int << "\n";
101-
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
102-
char_utils::get_char();
103-
option_shell();
104-
}
105-
else if (command == "mul") {
106-
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
107-
std::string num1;
108-
std::getline(std::cin, num1);
109-
int num1_int;
110-
try {
111-
num1_int = std::stoi(num1);
112-
}
113-
catch (std::invalid_argument& e) {
114-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
115-
std::this_thread::sleep_for(std::chrono::seconds(1));
116-
option_shell();
117-
}
118-
catch (std::out_of_range& e) {
119-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
120-
std::this_thread::sleep_for(std::chrono::seconds(1));
121-
option_shell();
122-
}
123-
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
124-
std::string num2;
125-
std::getline(std::cin, num2);
126-
int num2_int;
127-
try {
128-
num2_int = std::stoi(num2);
129-
}
130-
catch (std::invalid_argument& e) {
131-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
132-
}
133-
catch (std::out_of_range& e) {
134-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
135-
}
136-
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int * num2_int << "\n";
137-
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
138-
char_utils::get_char();
139-
option_shell();
140-
}
141-
else if (command == "div") {
142-
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
143-
std::string num1;
144-
std::getline(std::cin, num1);
145-
int num1_int;
146-
try {
147-
num1_int = std::stoi(num1);
148-
}
149-
catch (std::invalid_argument& e) {
150-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
151-
std::this_thread::sleep_for(std::chrono::seconds(1));
152-
option_shell();
153-
}
154-
catch (std::out_of_range& e) {
155-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
156-
std::this_thread::sleep_for(std::chrono::seconds(1));
157-
option_shell();
158-
}
159-
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
160-
std::string num2;
161-
std::getline(std::cin, num2);
162-
int num2_int;
163-
try {
164-
num2_int = std::stoi(num2);
165-
}
166-
catch (std::invalid_argument& e) {
167-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
168-
}
169-
catch (std::out_of_range& e) {
170-
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
171-
}
172-
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int / num2_int << "\n";
173-
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
174-
char_utils::get_char();
175-
option_shell();
176-
}
177-
else {
178-
option_shell();
179-
}
180-
}
181-
#endif
1+
#include <iostream>
2+
#include <string>
3+
#include <thread>
4+
#include "console.hpp"
5+
#include "ansi.hpp"
6+
#include "char.hpp"
7+
8+
#ifndef CALCULATOR_SHELL_HPP
9+
#define CALCULATOR_SHELL_HPP
10+
inline void option_shell() {
11+
std::string command;
12+
std::cout << ansi::CYAN << ">> " << ansi::RESET << ansi::GREEN;
13+
std::getline(std::cin, command);
14+
if (command == "help") {
15+
std::cout << ansi::BOLD << ansi::ITALIC << ansi::CYAN;
16+
std::cout << "Commands:\n";
17+
std::cout << "help - show this help message\n";
18+
std::cout << "exit - exit the shell\n";
19+
std::cout << "clear - clear the screen\n";
20+
std::cout << "sub - substract two numbers\n";
21+
std::cout << "add - add two numbers\n";
22+
std::cout << "mul - multiply two numbers\n";
23+
std::cout << "div - divide two numbers\n";
24+
std::cout << ansi::RESET;
25+
option_shell();
26+
}
27+
else if (command == "exit") {
28+
}
29+
else if (command == "clear") {
30+
console::clear();
31+
option_shell();
32+
}
33+
else if (command == "sub") {
34+
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
35+
std::string num1;
36+
std::getline(std::cin, num1);
37+
int num1_int;
38+
try {
39+
num1_int = std::stoi(num1);
40+
}
41+
catch (std::invalid_argument& e) {
42+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
43+
std::this_thread::sleep_for(std::chrono::seconds(1));
44+
option_shell();
45+
}
46+
catch (std::out_of_range& e) {
47+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
48+
std::this_thread::sleep_for(std::chrono::seconds(1));
49+
option_shell();
50+
}
51+
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
52+
std::string num2;
53+
std::getline(std::cin, num2);
54+
int num2_int;
55+
try {
56+
num2_int = std::stoi(num2);
57+
}
58+
catch (std::invalid_argument& e) {
59+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
60+
}
61+
catch (std::out_of_range& e) {
62+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
63+
}
64+
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int - num2_int << "\n";
65+
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
66+
char_utils::get_char();
67+
option_shell();
68+
}
69+
else if (command == "add") {
70+
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
71+
std::string num1;
72+
std::getline(std::cin, num1);
73+
int num1_int;
74+
try {
75+
num1_int = std::stoi(num1);
76+
}
77+
catch (std::invalid_argument& e) {
78+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
79+
std::this_thread::sleep_for(std::chrono::seconds(1));
80+
option_shell();
81+
}
82+
catch (std::out_of_range& e) {
83+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
84+
std::this_thread::sleep_for(std::chrono::seconds(1));
85+
option_shell();
86+
}
87+
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
88+
std::string num2;
89+
std::getline(std::cin, num2);
90+
int num2_int;
91+
try {
92+
num2_int = std::stoi(num2);
93+
}
94+
catch (std::invalid_argument& e) {
95+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
96+
}
97+
catch (std::out_of_range& e) {
98+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
99+
}
100+
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int + num2_int << "\n";
101+
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
102+
char_utils::get_char();
103+
option_shell();
104+
}
105+
else if (command == "mul") {
106+
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
107+
std::string num1;
108+
std::getline(std::cin, num1);
109+
int num1_int;
110+
try {
111+
num1_int = std::stoi(num1);
112+
}
113+
catch (std::invalid_argument& e) {
114+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
115+
std::this_thread::sleep_for(std::chrono::seconds(1));
116+
option_shell();
117+
}
118+
catch (std::out_of_range& e) {
119+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
120+
std::this_thread::sleep_for(std::chrono::seconds(1));
121+
option_shell();
122+
}
123+
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
124+
std::string num2;
125+
std::getline(std::cin, num2);
126+
int num2_int;
127+
try {
128+
num2_int = std::stoi(num2);
129+
}
130+
catch (std::invalid_argument& e) {
131+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
132+
}
133+
catch (std::out_of_range& e) {
134+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
135+
}
136+
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int * num2_int << "\n";
137+
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
138+
char_utils::get_char();
139+
option_shell();
140+
}
141+
else if (command == "div") {
142+
std::cout << ansi::CYAN << "Enter first number: " << ansi::RESET;
143+
std::string num1;
144+
std::getline(std::cin, num1);
145+
int num1_int;
146+
try {
147+
num1_int = std::stoi(num1);
148+
}
149+
catch (std::invalid_argument& e) {
150+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
151+
std::this_thread::sleep_for(std::chrono::seconds(1));
152+
option_shell();
153+
}
154+
catch (std::out_of_range& e) {
155+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
156+
std::this_thread::sleep_for(std::chrono::seconds(1));
157+
option_shell();
158+
}
159+
std::cout << ansi::CYAN << "Enter second number: " << ansi::RESET;
160+
std::string num2;
161+
std::getline(std::cin, num2);
162+
int num2_int;
163+
try {
164+
num2_int = std::stoi(num2);
165+
}
166+
catch (std::invalid_argument& e) {
167+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
168+
}
169+
catch (std::out_of_range& e) {
170+
std::cout << ansi::RED << e.what() << ansi::RESET << "\n";
171+
}
172+
std::cout << ansi::GREEN << "Result: " << ansi::RESET << num1_int / num2_int << "\n";
173+
std::cout << ansi::CYAN << "Press any key to continue...\n" << ansi::RESET;
174+
char_utils::get_char();
175+
option_shell();
176+
}
177+
else {
178+
option_shell();
179+
}
180+
}
181+
#endif

0 commit comments

Comments
 (0)