golang-exercises/tcell-practice/main.go

52 lines
909 B
Go
Raw Normal View History

2024-03-18 09:13:29 +01:00
package main
import (
"fmt"
"log"
"os"
2024-03-18 09:13:29 +01:00
"time"
"github.com/gdamore/tcell/v2"
)
func main() {
fmt.Println()
screen, err := tcell.NewScreen()
2024-03-18 09:13:29 +01:00
if err != nil {
log.Fatalf("%v", err)
}
if err := screen.Init(); err != nil {
2024-03-18 09:13:29 +01:00
log.Fatalf("%v", err)
}
x, y := 0, 0
2024-03-18 09:13:29 +01:00
//defStyle := tcell.StyleDefault.Background
defStyle := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
screen.SetStyle(defStyle)
go Run(x, y, screen, defStyle)
2024-03-18 09:13:29 +01:00
for {
switch event := screen.PollEvent().(type) {
case *tcell.EventResize:
screen.Sync()
case *tcell.EventKey:
switch event.Key() == tcell.KeyEscape || event.Key() == tcell.KeyCtrlC {
case true:
screen.Fini()
os.Exit(0)
}
}
}
2024-03-18 09:13:29 +01:00
}
2024-03-18 09:13:29 +01:00
func Run(x int, y int, screen tcell.Screen, defStyle tcell.Style) {
for {
screen.SetContent(x, y, 'A', nil, defStyle)
screen.Show()
x++
y++
2024-03-18 09:13:29 +01:00
time.Sleep(time.Second)
}
}