diff --git a/tcell-practice/main.go b/tcell-practice/main.go index 6cc3db1..fc61946 100644 --- a/tcell-practice/main.go +++ b/tcell-practice/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" "time" "github.com/gdamore/tcell/v2" @@ -10,22 +11,38 @@ import ( func main() { fmt.Println() - s, err := tcell.NewScreen() + screen, err := tcell.NewScreen() if err != nil { log.Fatalf("%v", err) } - if err := s.Init(); err != nil { + if err := screen.Init(); err != nil { log.Fatalf("%v", err) } //defStyle := tcell.StyleDefault.Background defStyle := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset) - s.SetStyle(defStyle) + screen.SetStyle(defStyle) + go Run(screen, defStyle) + 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) + } + } + } - s.Clear() - s.SetContent(20, 20, 'A', nil, defStyle) +} +func Run(screen tcell.Screen, defStyle tcell.Style) { + for { + screen.SetContent(20, 20, 'A', nil, defStyle) + screen.Show() time.Sleep(time.Second) } }