Skip to content

Refactor terminal modes to make them usable with effect systems #27

@kapunga

Description

@kapunga

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(): () => Unit

On 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions