Teaching my kid how to program and using Nim as an alternative to Python.
Trying to write simple games that output to stdout in windows terminal. But echoing rows of strings, sleeping, and repeating results in the text flowing onto the terminal too slowly, so it appears to be hopping around as it fills in before sleeping. I've done this same sort of thing in Python on my Mac with no visual issues.
I'm wondering if this is a windows terminal issue or if there's a better way to dump a bunch of text out of Nim between ticks. My first thought was to buffer my rows of strings to some temporary space and then echo the entire game screen all at once, but I was either approaching it the wrong way of else windows terminal is too slow to write multiple rows quickly without visual glitches.
This is easily reproduced by creating a simple Nim program that dumps the alphabet to the terminal, inserting a newline every x characters, sleeping for 0.5 seconds using os.sleep, and clearing the screen using terminal.eraseScreen; all in a loop.
Anyone have advice on how to accomplish a terminal based game in Nim? Thanks in advance!
I could squeeze a bit more performance out of a Linux terminal by only updating characters that changed between frames, but the Linux terminal works much differently than the Windows console.
In fact, the Windows console is buffered, and can probably be controlled much faster with the WinAPI functions described here https://docs.microsoft.com/en-us/windows/console/console-functions. I'm not sure if all of those are in the winlean module though, you may have to check out winim for complete functionality.
Have a look at illwill this does double buffering the output and read the input keys asyncronously
https://github.com/johnnovak/illwill
If you need buttons etc you could also have a look at my illwillwidgets library:
https://github.com/enthus1ast/illwillWidgets
Or as araq suggest use sdl2 or one of the other pure nim game engines, or godot (there is also a nim binding to godot)