-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I started trying to build an application with Cats-Effect and for my use case, the way modes are currently implemented, I can't wrap an IO with a mode. As an example:
_ <- Terminal.run { Terminal.raw { fs2.io.stdinUtf8[IO](16) } }Terminal.run returns the stream before it is evaluated and nothing happens.
I was trying to figure out a work around when it occurred to me that the only thing we really need to make this workable would be to make terminal modes use a stack as well as how other effects do it. What I propose is teasing apart setting a mode and push that down into the low level terminal, and lift the try with resources semantics into the higher level effect. What we would have would be:
/** Put the terminal into raw mode and return a thunk to revert it.
* This would live in JLineTerminal, etc.
*/
def pushRawMode(): () => UnitOn the higher level effect we would call pushRawMode(), then push the thunk onto a stack of thunks. We could keep Terminal.raw as is, but also expose the push and pop semantics so they could be used in something like IO.bracket.