Skip to content

Using Haskeline with a PseudoTerminal #147

@NorfairKing

Description

@NorfairKing

I'd like to use haskeline for a browser-based terminal interface.
(See smos.online.)

I got something hacky working like this:

    -- TODO try to use the special TTY handles instead so history works too.
    customRunInputT :: InputT IO a -> IO a
    customRunInputT inputT = do
      historyRef <- newIORef Haskeline.emptyHistory
      withBehavior (useFileHandle inputH) $ \rt -> do
        let runTerm =
              rt
                { putStrOut = \s -> do
                    hPutStr outputH s
                    hFlush outputH
                }
        runReaderT
          ( runReaderT
              ( Haskeline.runKillRing
                  ( runReaderT
                      ( runReaderT (unInputT inputT) runTerm
                      )
                      historyRef
                  )
              )
              Haskeline.defaultPrefs
          )
          Haskeline.defaultSettings

However, pressing the up arrow key doesn't show me the history but a control sequence instead.
I've also tried to write this:

givenTtyHandles :: Handle -> Handle -> MaybeT IO Handles
givenTtyHandles inh outh = do
    outEH <- inCodingMode outh
    return Handles
            { hIn = externalHandle inh
            , hOut = outEH
            , closeHandles = pure () -- Don't close them
            }

and then the history works but the input is no longer echoed, even with hSetExcho inh and hSetBuffering inh NoBuffering.

Is this a use-case that you would like to support?

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