|
8 | 8 |
|
9 | 9 | using namespace std; |
10 | 10 |
|
11 | | -int Printer::getTerminalWidth() { |
12 | | - // Instantiate a window size struct |
13 | | - struct winsize w; |
14 | | - // Setting some magic numbers for file descriptor and request. and passing the window size struct |
15 | | - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); |
16 | | - // Returning the width columns |
17 | | - return w.ws_col; |
| 11 | +int Printer::getTerminalWidth() |
| 12 | +{ |
| 13 | + // Instantiate a window size struct |
| 14 | + struct winsize w; |
| 15 | + // Setting some magic numbers for file descriptor and request. and passing the window size struct |
| 16 | + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); |
| 17 | + // Returning the width columns |
| 18 | + return w.ws_col; |
18 | 19 | } |
19 | 20 |
|
20 | | -void Printer::clearScreen() { |
21 | | - // \033[2J clears the screen, \033[H moves cursor to top |
22 | | - std::cout << "\033[2J\033[H"; |
| 21 | +void Printer::clearScreen() |
| 22 | +{ |
| 23 | + // \033[2J clears the screen, \033[H moves cursor to top |
| 24 | + std::cout << "\033[2J\033[H"; |
23 | 25 | } |
24 | 26 |
|
25 | | -void Printer::printHeader() { |
26 | | - Printer::clearScreen(); |
27 | | - |
28 | | - std::vector<std::string> myArt = { |
29 | | - "****************************************************", |
30 | | - "* ╻ ╻┏━┓ ┏━┓┏━╸┏━┓┏┓╻ *", |
31 | | - "* ┏╋┛┣━┛ ┗━┓┃ ┣━┫┃┗┫ *", |
32 | | - "* ╹ ╹╹ ┗━┛┗━╸╹ ╹╹ ╹ *", |
33 | | - "* -------------------------------------------- *", |
34 | | - "* 01101000 01110101 01101101 01100001 01101110 *", |
35 | | - "* -------------------------------------------- *", |
36 | | - "****************************************************\n\n", |
37 | | - }; |
38 | | - |
39 | | - int width = Printer::getTerminalWidth(); |
40 | | - Printer::printCentered(myArt, width); |
| 27 | +void Printer::printHeader() |
| 28 | +{ |
| 29 | + Printer::clearScreen(); |
| 30 | + |
| 31 | + std::vector<std::string> myArt = { |
| 32 | + "****************************************************", |
| 33 | + "* ╻ ╻┏━┓ ┏━┓┏━╸┏━┓┏┓╻ *", |
| 34 | + "* ┏╋┛┣━┛ ┗━┓┃ ┣━┫┃┗┫ *", |
| 35 | + "* ╹ ╹╹ ┗━┛┗━╸╹ ╹╹ ╹ *", |
| 36 | + "* -------------------------------------------- *", |
| 37 | + "* 01101000 01110101 01101101 01100001 01101110 *", |
| 38 | + "* -------------------------------------------- *", |
| 39 | + "****************************************************\n\n", |
| 40 | + }; |
| 41 | + |
| 42 | + int width = Printer::getTerminalWidth(); |
| 43 | + Printer::printCentered(myArt, width); |
41 | 44 | } |
42 | 45 |
|
43 | | -void Printer::printCentered(const vector<string>& art, int terminalWidth) { |
44 | | - size_t maxWidth = 0; |
45 | | - const std::string COLOR = "\033[33m"; |
46 | | - const std::string RESET = "\033[0m"; |
| 46 | +void Printer::printCentered(const vector<string>& art, int terminalWidth) |
| 47 | +{ |
| 48 | + size_t maxWidth = 0; |
| 49 | + const std::string COLOR = "\033[33m"; |
| 50 | + const std::string RESET = "\033[0m"; |
47 | 51 |
|
48 | | - // Step 1: Find the widest line in the art |
49 | | - for (const std::string& line : art) { |
50 | | - maxWidth = std::max(maxWidth, line.length()); |
51 | | - } |
| 52 | + // Step 1: Find the widest line in the art |
| 53 | + for (const std::string& line : art) |
| 54 | + { |
| 55 | + maxWidth = std::max(maxWidth, line.length()); |
| 56 | + } |
52 | 57 |
|
53 | | - // Step 2: Calculate padding based on the widest line |
54 | | - int padding = (terminalWidth - (int)maxWidth) / 2; |
55 | | - if (padding < 0) padding = 0; // Prevent errors if terminal is too narrow |
| 58 | + // Step 2: Calculate padding based on the widest line |
| 59 | + int padding = (terminalWidth - (int) maxWidth) / 2; |
| 60 | + if (padding < 0) |
| 61 | + padding = 0; // Prevent errors if terminal is too narrow |
56 | 62 |
|
57 | | - // Step 3: Print every line using the SAME padding |
58 | | - for (const std::string& line : art) { |
59 | | - std::cout << std::string(padding, ' ') << COLOR << line << RESET << std::endl; |
60 | | - } |
| 63 | + // Step 3: Print every line using the SAME padding |
| 64 | + for (const std::string& line : art) |
| 65 | + { |
| 66 | + std::cout << std::string(padding, ' ') << COLOR << line << RESET << std::endl; |
| 67 | + } |
61 | 68 | } |
0 commit comments