-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pomodoro.h
71 lines (59 loc) · 2.51 KB
/
Pomodoro.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <thread>
class PomodoroTimer {
public:
void start() {
std::cout << "\nBienvenido al temporizador Pomodoro!" << std::endl;
bool exit = false;
while (!exit) {
int minutes;
std::cout << "\nPor favor ingrese la duración del temporizador en minutos (minimo 1, maximo 60), o ingrese 0 para salir: ";
std::cin >> minutes;
if (minutes == 0) {
std::cout << "\nSaliendo del temporizador Pomodoro..." << std::endl;
return;
}
else if (minutes < 1 || minutes > 60) {
std::cout << "\nEl tiempo debe estar entre 1 y 60 minutos." << std::endl;
}
else {
pomodoro(minutes, false);
system("CLS");
char choice;
std::cout << "\n¿Desea descansar? (s/n): ";
std::cin >> choice;
if (choice == 's' || choice == 'S') {
std::cout << "\nDescansando por 1 minuto..." << std::endl;
pomodoro(1, true);
}
else {
std::cout << "\nComenzando nuevo pomodoro..." << std::endl;
}
std::cout << "\nPresione cualquier tecla para regresar al menú principal." << std::endl;
std::cin.ignore();
std::cin.get();
system("CLS");
}
}
}
private:
void pomodoro(int minutes, bool is_break) {
auto end_time = std::chrono::system_clock::now() + std::chrono::minutes(minutes);
while (std::chrono::system_clock::now() < end_time) {
std::this_thread::sleep_for(std::chrono::seconds(1));
auto remaining_time = std::chrono::duration_cast<std::chrono::seconds>(end_time - std::chrono::system_clock::now()).count();
int minutes = remaining_time / 60;
int seconds = remaining_time % 60;
std::cout << "\rTiempo restante" << (is_break ? " de descanso" : "") << ": " << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds << std::flush;
}
std::cout << "\r¡Tiempo completado" << (is_break ? " de descanso" : "") << "!" << std::endl;
system("CLS");
std::cout << "\nPresione cualquier tecla para regresar al menú principal." << std::endl;
std::cin.ignore();
std::cin.get();
system("CLS");
}
};