优化: 空闲 CPU 归零,事件驱动渲染+输入等待
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,3 +23,4 @@ Thumbs.db
|
|||||||
*.exe
|
*.exe
|
||||||
*.exe.old
|
*.exe.old
|
||||||
*~
|
*~
|
||||||
|
u-tabs.prof
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.update.Checking = false
|
m.update.Checking = false
|
||||||
case cacheFlushMsg:
|
case cacheFlushMsg:
|
||||||
m.flushCache()
|
m.flushCache()
|
||||||
|
// 只在仍有脏数据时继续调度,避免空转
|
||||||
|
if m.cacheDirty {
|
||||||
|
return m, cacheFlushTick()
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
case tea.QuitMsg:
|
case tea.QuitMsg:
|
||||||
m.flushCache()
|
m.flushCache()
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -13,7 +13,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
internal.InitData()
|
internal.InitData()
|
||||||
m := internal.NewModel()
|
m := internal.NewModel()
|
||||||
p := tea.NewProgram(m, tea.WithFPS(5))
|
p := tea.NewProgram(m, tea.WithFPS(0))
|
||||||
if _, err := p.Run(); err != nil {
|
if _, err := p.Run(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "启动失败: %v\n", err)
|
fmt.Fprintf(os.Stderr, "启动失败: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user