-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountDown.cpp
More file actions
58 lines (44 loc) · 1.78 KB
/
countDown.cpp
File metadata and controls
58 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Terminal++.hpp"
void countdown(const int seconds) {
Printer printer; // Create a Terminal object for this thread
printer.setTextColor(Color::Cyan); // Set text color to Cyan
Screen::clear();
Cursor::hide(); // hiding the cursor
printer.println("Starting countdown...");
Terminal::sleep(1000);
Screen::clear();
// Loop through the countdown
for (int i = seconds; i > 0; --i) {
Cursor::moveTo(1, 1); // Move cursor to the top-left corner
printer.println("Countdown: ", i, " seconds remaining...");
Printer::flush(); // Flush the output stream
Terminal::sleep(1000); // Sleep for 1 second
}
Screen::clear();
Cursor::hide();
Cursor::moveTo(1, 1); // Move cursor to the top-left corner
printer.setTextColor(Color::Green); // Change color to Green for completion
printer.println("Time's up!"); // Print completion message
}
int main() {
Screen::clear(); // Clear the terminal screen
Terminal terminal; // Create a Terminal object for the main thread
Printer printer;
printer.println("Welcome to the Countdown Timer!");
printer.print("Enter the countdown time in seconds: ");
int seconds;
std::cin >> seconds; // Get user input for countdown time
std::cin.ignore(); // Ignore the newline character after input
// Start the countdown in a separate thread
terminal.nonBlock([&]() {
countdown(seconds);
});
// wait for the countdown to finish
terminal.awaitCompletion();
// Main thread can do other things or just wait
printer.println("Press any key to exit...");
// Wait for user input before exiting
Input::getChar();
Screen::clear();
printer.println("Exiting the timer. Goodbye!");
}