Stream: show and tell

Topic: TUI using basic-cli


view this post on Zulip Luke Boswell (Jun 18 2023 at 06:05):

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.

tui-example-2.gif

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.

view this post on Zulip Notification Bot (Jun 18 2023 at 06:05):

A message was moved here from #show and tell > Vim syntax highlighting by Luke Boswell.

view this post on Zulip Luke Boswell (Jun 18 2023 at 06:17):

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.

view this post on Zulip Brendan Hansknecht (Jun 25 2023 at 15:43):

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.

view this post on Zulip Luke Boswell (Jun 25 2023 at 22:51):

The call to read from stdin blocks though. I had trouble making that just return immediately if there is nothing in the buffer.

view this post on Zulip Brendan Hansknecht (Jun 25 2023 at 23:21):

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.

view this post on Zulip Artur Swiderski (Nov 24 2023 at 16:52):

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 ??

view this post on Zulip Anton (Nov 24 2023 at 17:02):

@Luke Boswell has experience with similar stuff and should be able to point you to some helpful sources.

view this post on Zulip Luke Boswell (Nov 24 2023 at 19:02):

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.

view this post on Zulip Luke Boswell (Nov 24 2023 at 19:14):

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

view this post on Zulip Brendan Hansknecht (Nov 24 2023 at 19:29):

Wouldn't this feature more be akin to a tui textbox?

view this post on Zulip Brendan Hansknecht (Nov 24 2023 at 19:29):

tui textboxes have error key control and editability

view this post on Zulip Artur Swiderski (Nov 24 2023 at 20:17):

thx for ideas , is there possibility to make sleep in Roc currently ?

view this post on Zulip Luke Boswell (Nov 24 2023 at 20:21):

https://www.roc-lang.org/packages/basic-cli/Sleep


Last updated: Jul 05 2025 at 12:14 UTC