-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhappy.py
More file actions
307 lines (263 loc) · 12.3 KB
/
happy.py
File metadata and controls
307 lines (263 loc) · 12.3 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
码年大吉 — Claude Code 风格新春贺卡 2026
丙午马年 · Year of the Fire Horse
"""
import os
import sys
# Windows UTF-8 兼容:设置控制台代码页 + stdout 编码
if sys.platform == "win32":
os.system("chcp 65001 > nul")
# 启用 Windows Terminal VT100 模式,避免 Rich 回退到 legacy 渲染
try:
import ctypes
kernel32 = ctypes.windll.kernel32
# STD_OUTPUT_HANDLE = -11
handle = kernel32.GetStdHandle(-11)
# ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
mode = ctypes.c_ulong()
kernel32.GetConsoleMode(handle, ctypes.byref(mode))
kernel32.SetConsoleMode(handle, mode.value | 0x0004)
except Exception:
pass
# 确保 stdout 使用 UTF-8
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8")
from rich.console import Console
from rich.text import Text
from rich.panel import Panel
from rich.table import Table
from rich import box
console = Console(force_terminal=True)
# ─── ASCII LOGO ────────────────────────────────────────────────
def build_logo() -> Text:
"""构建 ASCII LOGO + 副标题"""
# HAPPY (居中于 CODE YEAR) + CODE YEAR,每行 pad 到等宽
happy_lines = [
" ██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗",
" ██║ ██║██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝",
" ███████║███████║██████╔╝██████╔╝ ╚████╔╝ ",
" ██╔══██║██╔══██║██╔═══╝ ██╔═══╝ ╚██╔╝ ",
" ██║ ██║██║ ██║██║ ██║ ██║ ",
" ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ",
]
code_year_lines = [
" ██████╗ ██████╗ ██████╗ ███████╗ ██╗ ██╗███████╗ █████╗ ██████╗ ",
"██╔════╝██╔═══██╗██╔══██╗██╔════╝ ╚██╗ ██╔╝██╔════╝██╔══██╗██╔══██╗",
"██║ ██║ ██║██║ ██║█████╗ ╚████╔╝ █████╗ ███████║██████╔╝",
"██║ ██║ ██║██║ ██║██╔══╝ ╚██╔╝ ██╔══╝ ██╔══██║██╔══██╗",
"╚██████╗╚██████╔╝██████╔╝███████╗ ██║ ███████╗██║ ██║██║ ██║ ",
" ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝",
]
text = Text()
from rich.cells import cell_len
all_lines = happy_lines + code_year_lines
max_w = max(cell_len(l) for l in all_lines)
term_w = console.width
pad_left = max((term_w - max_w) // 2, 0)
prefix = " " * pad_left
for line in all_lines:
text.append(prefix + line + "\n", style="bold bright_magenta")
text.append("\n")
subtitle = "🐴 码 年 大 吉 · 丙午年 · 万 码 奔 腾 🐴"
sub_pad = max((term_w - cell_len(subtitle)) // 2, 0)
text.append(" " * sub_pad + subtitle, style="bold yellow")
return text
def build_info() -> Table:
"""构建信息区:左侧 Clawd 吉祥物 + 右侧启动信息"""
# Clawd 吉祥物 (Claude Code mascot)
clawd = Text()
clawd.append(" ▐▛███▜▌ \n", style="rgb(215,119,87)")
clawd.append("▝▜█████▛▘\n", style="rgb(215,119,87)")
clawd.append(" ▘▘ ▝▝\n", style="rgb(215,119,87)")
# 右侧信息
info = Text()
info.append("Welcome to 丙午马年 v2026.2.17\n", style="bold bright_white")
info.append("cwd: ", style="dim white")
info.append("~/2026/todo\n", style="blue")
info.append("model: ", style="dim white")
info.append("claude-opus-4.6", style="blue")
info.append(" (码力全开版)\n", style="blue")
info.append("Tip: ", style="dim white")
info.append("新的一年多学习,也要多休息", style="bright_cyan")
tbl = Table(show_header=False, show_edge=False, box=None,
padding=(0, 1), expand=False)
tbl.add_column(width=11)
tbl.add_column()
tbl.add_row(clawd, info)
return tbl
def build_plan_panel(height: int = None) -> Panel:
"""构建左侧 Plan 面板:模拟 Claude Code 需求确认复选框"""
content = Text()
content.append(" 2026 年度愿望清单确认\n", style="bold bright_white")
content.append(" 请确认你的新年需求:\n\n", style="dim white")
# ── 通用祝福 ──
content.append(" ◈ 今年生活上要:\n", style="bold cyan")
general = [
("身体健康", "uptime: 365d, 0 crashes, 0 hotfixes"),
("财运亨通", "bonus = int('overflow')"),
("无忧无虑", "rm -rf ~/anxiety ~/stress ~/self-doubt"),
("达成目标", "assert all(goal.done for goal in y2026)"),
]
for wish, detail in general:
content.append(" ☑ ", style="bold green")
content.append(wish, style="bold bright_white")
content.append(" — ", style="dim white")
content.append(detail + "\n", style="dim white")
content.append("\n")
# ── 学生党 ──
content.append(" ◈ 今年学业上要:\n", style="bold cyan")
student = [
("一次上岸", "offer = recruit.accept(top_choice)"),
("连发Paper", "papers.append(CCF_A)"),
("每个idea都work", "for idea in brain: pass"),
("显卡自由", "gpu_cluster = [H200] * 128"),
("经费充足", "grant.balance = Decimal('Infinity')"),
]
for wish, detail in student:
content.append(" ☑ ", style="bold green")
content.append(wish, style="bold bright_white")
content.append(" — ", style="dim white")
content.append(detail + "\n", style="dim white")
content.append("\n")
# ── 打工人 ──
content.append(" ◈ 今年工作上要:\n", style="bold cyan")
worker = [
("升职加薪", "salary += salary * 0.5"),
("需求不变更", "git revert product_manager --hard"),
("准时下班", "crontab -e # 18:00 /usr/bin/go-home"),
("Vibe Coding 一次过", "cursor.run(prompt) == LGTM"),
("配环境不报错", "pip install . && exit 0 # 一次搞定"),
]
for wish, detail in worker:
content.append(" ☑ ", style="bold green")
content.append(wish, style="bold bright_white")
content.append(" — ", style="dim white")
content.append(detail + "\n", style="dim white")
content.append("\n")
content.append(" ─────────────────────────────────\n", style="dim white")
content.append(" > 你的选择:", style="dim white")
content.append("我全都要!\n", style="bold yellow")
content.append(" ✓ 已确认,正在部署到 2026...\n", style="bold green")
return Panel(
content,
title="[bold cyan]Plan[/bold cyan]",
border_style="cyan",
padding=(1, 2),
expand=True,
height=height,
)
def build_greetings_panel(height: int = None) -> Panel:
"""构建右侧面板:git diff + commit 风格的辞旧迎新"""
content = Text()
# diff 头部
content.append("diff --git a/2025.life b/2026.life\n", style="bold bright_white")
content.append("--- a/2025.life\n", style="bold bright_white")
content.append("+++ b/2026.life\n", style="bold bright_white")
content.append("@@ -1,8 +1,8 @@\n\n", style="bright_cyan")
# diff 内容:删红增绿
diffs = [
("- 久坐不动,熬夜通宵", "+ 规律作息,精力充沛"),
("- 论文被拒,导师已读不回", "+ 连中顶会,导师疯狂点赞"),
("- 配环境三天,跑代码三分钟", "+ 一键部署,开箱即用"),
("- 显卡排队,Token 耗尽", "+ 算力无限,Token 自由"),
("- 需求变更,通宵加班", "+ 准时下班,需求冻结"),
("- 玄学 bug,重启也没用", "+ 代码优雅,零 warning"),
("- 余额不足,花呗还款", "+ 财务自由,被动收入"),
("- 焦虑内耗,精神紧绷", "+ 心态平和,快乐充实"),
]
for minus, plus in diffs:
content.append(minus + "\n", style="red")
content.append(plus + "\n", style="green")
# git 操作
content.append("\n")
content.append("$ ", style="dim white")
content.append("git add .\n", style="bright_cyan")
content.append("$ ", style="dim white")
content.append('git commit -m "辞旧迎新 2026"\n', style="bright_cyan")
content.append("[main 2026] 辞旧迎新 2026\n", style="dim white")
content.append(" 8 files changed, 8 insertions(+), 8 deletions(-)\n", style="dim white")
content.append("$ ", style="dim white")
content.append("git push origin main\n", style="bright_cyan")
content.append("✓ 已推送至 2026 🐴\n", style="bold green")
return Panel(
content,
title="[bold yellow]Execution[/bold yellow]",
border_style="yellow",
padding=(1, 2),
height=height,
)
def build_status_bar() -> Panel:
"""构建底部状态栏"""
bar = Text()
bar.append(" [Plan: 新春]", style="white on grey11")
bar.append(" opus-4.6-cny", style="white on grey11")
bar.append(" 🐴 马年大吉", style="white on grey11")
bar.append(" luck: ∞", style="white on grey11")
bar.append(" bugs: 0", style="white on grey11")
bar.append(" hair: 100%", style="white on grey11")
bar.append(" fortune: 码到成功", style="white on grey11")
bar.append(" ", style="on grey11")
return Panel(
bar,
box=box.SIMPLE,
style="on grey11",
padding=0,
)
def main():
# 清屏
os.system("cls" if sys.platform == "win32" else "clear")
width = console.width
narrow = width < 100
# ① LOGO 区
logo = build_logo()
console.print(logo)
console.print()
# ② 信息区
info = build_info()
console.print(info)
console.print()
# ③ 主体区
plan_panel = build_plan_panel()
greetings_panel = build_greetings_panel()
if narrow:
# 窄屏:上下堆叠
console.print(plan_panel)
console.print(greetings_panel)
else:
# 宽屏:左右分栏 (3:2),等高对齐
left_w = int(width * 3 / 5)
right_w = width - left_w
left_opts = console.options.update_width(left_w)
right_opts = console.options.update_width(right_w)
left_h = len(console.render_lines(plan_panel, options=left_opts))
right_h = len(console.render_lines(greetings_panel, options=right_opts))
target_h = max(left_h, right_h)
# 重建面板,设置统一高度
plan_panel = build_plan_panel(height=target_h)
greetings_panel = build_greetings_panel(height=target_h)
table = Table(show_header=False, show_edge=False, box=None,
padding=0, expand=True)
table.add_column(ratio=3)
table.add_column(ratio=2)
table.add_row(plan_panel, greetings_panel)
console.print(table)
console.print()
# ④ 底部状态栏
status = build_status_bar()
console.print(status)
# ⑤ 模拟输入提示符
try:
user_input = console.input("[bold bright_white]> [/bold bright_white]")
except (EOFError, KeyboardInterrupt):
user_input = ""
if user_input.strip():
console.print(
"\n🐴 码到成功!祝你马年大吉!Happy 2026! 🐴\n",
style="bold yellow",
)
else:
console.print()
if __name__ == "__main__":
main()