I've been conducting various experiments for PR #54 which adds support for terminal raw mode to basic-cli
and made something I thought worth sharing. This code gist has my progress from today's effort. Basically all it does it draw a small "game map" to the screen and take user input from the keyboard. It validates most of the key requirements to build a small game or app using the terminal. Below is a gif which shows how it looks at the moment.
I had a go at making something that included the clock to tick the game loop over, but without Task.map2
to enable asynchronous IO in the platforms I don't think that is possible RN.
A message was moved here from #show and tell > Vim syntax highlighting by Luke Boswell.
Also, the "loading" screen is just to validate that it is possible to make a simple animation. There isn't actually anything being loaded here.
This should be possible without task.map2
, but you have to do is in a way that enables game tick mode and then keeps calling the same function that isn't main. So main would end with that call.
The call to read from stdin blocks though. I had trouble making that just return immediately if there is nothing in the buffer.
Ah, normally you don't read stdin but instead poll key presses for that kind of stuff, but yeah, i guess that could cause issues.
I have no idea but if I download roc as it is, will I be able to create application like this ?
I am interested to make it happen, to move cursor left when I am typing in prompt:
so I want inside my text application to be able to
aaaaaaa -> move left using arrows to be able to do this -> aaabbbbaaaaa
If I would be able to implement ctrl+u or home, it would be also great
any tips how to approach this topic ??
@Luke Boswell has experience with similar stuff and should be able to point you to some helpful sources.
Is it possible to do that using the terminal in any other languages? I'm not sure. The ANSI Escapes can get you some functionality, but are very limited and different terminals are wildy inconsistentent with how they support things. Using basic-cli as it current is should be capable of almost anything any other terminal UI app can do, with one major edception. We don't have Task.map2 which means everything has to run sequentially which is somewhat limiting.
You might be able to have a loop where you read from stdin, immediately print out and then read again. If user presses arrow keys change where the cursor is. So yeah, I think it should be possible using basic-cli RN
Wouldn't this feature more be akin to a tui textbox?
tui textboxes have error key control and editability
thx for ideas , is there possibility to make sleep in Roc currently ?
https://www.roc-lang.org/packages/basic-cli/Sleep
Last updated: Jul 05 2025 at 12:14 UTC