-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (38 loc) · 1.39 KB
/
Copy pathmain.cpp
File metadata and controls
50 lines (38 loc) · 1.39 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
#include "calendar.h"
#include "console.h"
#include <conio.h>
#include <iostream> // 用于输出错误信息
enum class Key{
Left = 75,
Right = 77,
Up = 72,
Down = 80,
Space = 32,
Esc = 27
};
constexpr int ExtKeyPrefix = 224; // 方向扩展键的第一字节
int main(){
console::setTitle("Calendar"); // 设置窗口标题为 Calendar
try{
Calendar cal;
while(true){
cal.calendarView();
auto key = _getch();
if(key == static_cast<int>(Key::Esc)) break; // Esc 退出程序
if(key == static_cast<int>(Key::Space)) cal.backToToday(); // Space 回到今天日期
if(key == ExtKeyPrefix){
key = _getch();
if(key == static_cast<int>(Key::Left)) cal.prevMonth(); // ← 上一月
if(key == static_cast<int>(Key::Right)) cal.nextMonth(); // → 下一月
if(key == static_cast<int>(Key::Up)) cal.prevYear(); // ↑ 上一年
if(key == static_cast<int>(Key::Down)) cal.nextYear(); // ↓ 下一年
}
}
}catch(const std::exception &e){
console::setColor(console::Color::RED); // 设置错误颜色为红色
std::cerr << "Error: " << e.what() << "\n";
console::setColor(console::Color::DEFAULT); // 恢复默认颜色
return 1;
}
return 0;
}