Just started with Nim and looking into writing a terminal application with it. My brain is completely into web development for the last decade so the old Turbo Pascal programs are long gone from my memory.
So the question is a simple one. I want to write a utility that runs from the terminal, shows an interface and you can move around and hit some (vim like) shortcuts.
My first guess would be as simple as a none ending loop:
while true:
readInput()
drawInterface()
This kind of works, but it feels limited and too linear. Let's say I want to deep scan folders during the app or any other action while the user is moving around. This will cause issues, I think.
Another approach would be threads, so I tried:
import asyncdispatch, times
proc main() {.async} =
readInput()
asyncCheck main()
runForEver()
So sure, this doesn't work because I'm missing some vital things that I can't seem to figure out what they are at the moment.
I looked at some examples online, but most examples with runForEver involve the Jester package. Which apparently has timers and or handles to allow the usage of runForEver.
Any tips on how to resolve the following:
Async != threads. readInput() will block regardless. You will need to use kbhit() equivalent code.
I did something similar in my CLI editor. Check it out, hope it helps.