Hi,
I am trying to implement a simple terminal game using the basic-cli platform. I am trying to read user input in a non blocking way. To simulate this I wanted to assing some time in the loop to read user input and ignore it if no input is received withing the given time. Does anyone know how to implement a function that receices a task and a time and returns the task result if the task completes or a Timeout error if the time runs out?
I don't think that is currently supported in basic cli. Someone would need to add the feature to the platform. Though it might be hard to add into the platform in a generic way with the current platform interface (without effect interpreters).
So probably would currently need to be added for specific operation.
I think you can probably achieve what you want with Tty.enableRawMode, see this example.
I am using Tty.enableRawMode, the example is almost what I wanted, except the input is blocking, because the GUI doenst neet to update if there is no user input. Maybe I do need to implement something to be able to add a timeout to a task
Right, I understand now
Or implement a turn based game with no idle animations :P
That seems easier :sweat_smile:
Yeah, this is something I've explored a bit while making terminal UI games. I came to the conclusion it's not possible without Task.map2 and the effect interpreters.
Luke Boswell said:
Yeah, this is something I've explored a bit while making terminal UI games. I came to the conclusion it's not possible without Task.map2 and the effect interpreters.
Is there a place to track the implementation of Task.map2? I've been working on using your roc-ansi package to create an MPD (Music Player Daemon) TUI client and I've gotten to the point where I can get and display the current playlist from the server, but it doesn't auto update since the next loop is stuck waiting for input.
I wanted to set a timeout on getting that input and jump to the next iteration of the loop, but it sounds like that's not possible with the basic-cli platform at the moment.
I think we know what needs to be done, but it just needs someone to implement it in the compiler. I think the next step from memory is to implement a paricular function which can take any roc type and give it a good name. Then this will enable the changes we need for glue. @Richard Feldman or @Folkert de Vries could give a better explanation. Is this something you would be interested in working on?
I don't think we've made an issie to track it or anything, so any updates or discussion would most likely be in zulip chat.
Oh actually I think @doubledup might be working on things?
OK, thanks. I did search in Zulip and Github issues, but thought maybe I'd missed something.
I think compiler work is beyond my abilities at this point, so I think I'll wait until someone one else is able to do it. There are plenty of other things I can play around with in the meantime.
Last updated: Jul 05 2025 at 12:14 UTC