Stream: ideas

Topic: Basic cli, disable raw mode on panic


view this post on Zulip Kilian Vounckx (Jun 25 2023 at 12:57):

I've been playing around with raw mode in the basic-cli platform to make a termion like package. It is a nice experience, but I found the following annoying.

At the moment, when an app using the basic-cli platform panics while raw mode is enabled, it will stay in raw mode. I think it would be nice if it automatically disabled raw mode. I think this should be possible in the roc_panic function somehow?

view this post on Zulip Anton (Jun 25 2023 at 13:28):

Good idea, you could use crossterm::terminal::is_raw_mode_enabled() and crossterm::terminal::disable_raw_mode() in the panic function. But I think it is better to set our own boolean when roc_fx_ttyModeRaw is called and checking that to prevent us from having to call more complex crossterm code on every panic. Can you write up an issue for that @Kilian Vounckx? If you want to implement that I'd be happy to review it :)

view this post on Zulip Kilian Vounckx (Jun 25 2023 at 13:36):

Issue raised!
This week I don't have the time to implement it, but if the issue is still open after that, I will tackle it

view this post on Zulip Anton (Jun 25 2023 at 13:38):

Thanks! sounds good :+1:

view this post on Zulip Kilian Vounckx (Jun 25 2023 at 20:21):

I have an hour or two free after studying now, so maybe I can handle it now. I've been looking at how crossterm does this function and they have a fancy mutex from the parking_lot crate containing an optional termios. That made me wonder, is basic-cli multithreaded? If so, is using an AtomicBool enough for handling that? If not, should we future-proof this implementation and make it atomic, or is this overhead too much? I would think not, because I don't expect the AtomicBool to be accessed too much (only when enabling or disabling, and on panics)

view this post on Zulip Kilian Vounckx (Jun 25 2023 at 20:23):

Also, if we have this bool, should we also expose a function to the platform? Something like isRawModeEnabled : Task Bool * in the Tty interface

view this post on Zulip Kilian Vounckx (Jun 25 2023 at 21:13):

I implemented it with an AtomicBool in this PR

view this post on Zulip Kilian Vounckx (Jun 25 2023 at 21:13):

I figured adding isRawEnabled should probably be its own PR

view this post on Zulip Kilian Vounckx (Jun 26 2023 at 10:43):

@Anton Just checking if you saw this as someone needs to review the PR :blush:

view this post on Zulip Anton (Jun 26 2023 at 10:44):

Yes, I'll check it in a bit :)


Last updated: Jun 16 2026 at 16:19 UTC