-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
127 lines (96 loc) · 3.2 KB
/
main.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <Windows.h>
#include <wchar.h>
#include <string>
int main()
{
// Set output mode to handle virtual terminal sequences
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE)
{
return GetLastError();
}
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode))
{
return GetLastError();
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hOut, dwMode))
{
return GetLastError();
}
auto inWaitMinutes = 0;
const auto strClear = std::wstring(100, L' ');
auto printT = []()
{
wprintf(L"Enter the waiting time(m): ");
};
auto printWaiting = [&inWaitMinutes, &strClear]()
{
wprintf(L"\x1b[1;1HWAITING: %d%s\x1b[?25l", inWaitMinutes, strClear.c_str());
wprintf(L"\n\x1b[1;31mPause: Click anywhere\nResume: <Enter>\r\x1b[0m");
};
printT();
while (scanf_s("%d", &inWaitMinutes) == 0)
{
while (getchar() != '\n');
printT();
}
printWaiting();
auto StartTime = clock();
auto CurrentTime = clock();
auto CalculateTaiming = [&StartTime, &CurrentTime] ()
{
auto SecToMin = 60.0;
return static_cast<double>((CurrentTime - StartTime)) / CLOCKS_PER_SEC / SecToMin;
};
auto PrintTimer = [&inWaitMinutes](auto CurrTimeSec)
{
const auto CurrTimeMinf = static_cast<int> (CurrTimeSec / 60);
const auto CurrTimeSecc = static_cast<int> (CurrTimeMinf * 60 - CurrTimeSec);
const auto CurrTimeSecf = CurrTimeSecc < 0 ? CurrTimeSecc * -1 : CurrTimeSecc;
auto LeftMin = inWaitMinutes;
auto LeftSec = 0;
LeftMin -= CurrTimeMinf;
LeftSec -= CurrTimeSecf;
if (LeftSec < 0)
{
LeftMin -= 1;
LeftSec = 60 - CurrTimeSecf;
}
auto strCommand = std::wstring(L"\x1b[42m");
if (LeftMin <= 0 && LeftSec <= 59 && LeftSec >10)
{
strCommand = std::wstring(L"\x1b[43m");
}
else if (LeftMin == 0 && LeftSec <= 10)
{
strCommand = std::wstring(L"\x1b[41m");
}
wprintf(L"\x1b[1;1HTIMER: %s%02d:%02d\x1b[0m\\ %02d:00\r",strCommand.c_str(), LeftMin, LeftSec, inWaitMinutes);
};
while (CalculateTaiming() <= static_cast <double> (inWaitMinutes))
{
const auto CurrTime = CalculateTaiming();
const auto CurrTimeSec = static_cast<int> (CurrTime * 60);
static auto LastSec = 0;
if (CurrTimeSec > LastSec)
{
PrintTimer(CurrTimeSec);
LastSec = CurrTimeSec;
}
Sleep(100);
//printf_s ("min: %f", CalculateTaiming());
CurrentTime = clock();
}
const auto CurrTime = CalculateTaiming();
const auto CurrTimeSec = static_cast<int> (CurrTime * 60);
PrintTimer(CurrTimeSec);
system ("call 1.mp3");
system ("start https://www.youtube.com/watch?v=gkROXD2kzyM");
system("pause");
return 0;
}