优化: 空闲 CPU 归零,事件驱动渲染+输入等待

This commit is contained in:
2026-06-08 13:35:41 +08:00
parent 80c90e6089
commit 32485c8ea7
3 changed files with 6 additions and 1 deletions

1
.gitignore vendored
View File

@@ -23,3 +23,4 @@ Thumbs.db
*.exe
*.exe.old
*~
u-tabs.prof

View File

@@ -108,6 +108,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.update.Checking = false
case cacheFlushMsg:
m.flushCache()
// 只在仍有脏数据时继续调度,避免空转
if m.cacheDirty {
return m, cacheFlushTick()
}
return m, nil
case tea.QuitMsg:
m.flushCache()

View File

@@ -13,7 +13,7 @@ import (
func main() {
internal.InitData()
m := internal.NewModel()
p := tea.NewProgram(m, tea.WithFPS(5))
p := tea.NewProgram(m, tea.WithFPS(0))
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "启动失败: %v\n", err)
os.Exit(1)