JoelOtter / termloop

Terminal-based game engine for Go, built on top of Termbox
Other
1.43k stars 83 forks source link

Programatic way to stop termloop #60

Closed chrisjd20 closed 3 years ago

chrisjd20 commented 3 years ago

Is there a way to programatically stop a termloop Game object? There is a Start function but no stop far as I can tell. Only way is to press key so far.

JoelOtter commented 3 years ago

Not really, though termloop doesn't really do any cleaning up so you're probably safe to just do whatever game-specific cleanup you require and then do os.Exit or similar

chrisjd20 commented 3 years ago

Thats basically what I ended up doing. Problem was closing it that way doesnt reset the terminal back to normal before exit so I had to do:

fmt.Print("\033[0m")
fmt.Print("\033[32m")
fmt.Print("\r\033[K")
fmt.Print("\033[H\033[2J")
os.Exit(0)

This should reset the terminal before exiting (on Nix at least).