mirror of
https://gitee.com/chuangxxt/share-copilot
synced 2026-12-01 23:27:52 +00:00
1.0.0
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
"time"
|
||||
)
|
||||
|
||||
func DisplayInfo(dataGetter func() []InfoItem, exitChan chan bool) {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
termbox.SetInputMode(termbox.InputEsc)
|
||||
|
||||
for {
|
||||
err := termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
y := 0
|
||||
data := dataGetter()
|
||||
for _, item := range data {
|
||||
drawString(0, y, item.Title, item.TitleColor, termbox.ColorDefault)
|
||||
drawString(len(item.Title)+1, y, item.Value, item.ValueColor, termbox.ColorDefault)
|
||||
y++
|
||||
}
|
||||
|
||||
err = termbox.Flush()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-exitChan:
|
||||
return // 通过退出通道退出循环
|
||||
default:
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func drawString(x, y int, text string, fg, bg termbox.Attribute) {
|
||||
for _, char := range text {
|
||||
termbox.SetCell(x, y, char, fg, bg)
|
||||
x++
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user