mirror of
https://gitee.com/chuangxxt/share-copilot
synced 2025-04-16 09:23:25 +00:00
51 lines
919 B
Go
51 lines
919 B
Go
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++
|
|
}
|
|
}
|