turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Turtle.Prelude.proc and Turtle.Prelude.shell don't pass keyboard input to ncurses programs.

Open crocket opened this issue 7 years ago • 1 comments

I needed to press space bar on an ncurses program, but proc and shell couldn't do it.

I had to replace them with import System.Process (spawnProcess, waitForProcess).

Below is how I use spawnProcess and waitForProcess.

{-# LANGUAGE OverloadedStrings #-}
module TermdownAlarm where

import System.Process (spawnProcess, waitForProcess)
import Control.Monad (void)
import Data.Text (Text, unpack)
import Turtle (proc, empty)
import System.Exit (ExitCode(..))

termdownAlarm :: Text -> Text -> Text -> IO ()
termdownAlarm title duration file = do
  exitCode <- spawnProcess "termdown"
    [ "--alt-format", "--no-figlet"
    , "--critical", "10", "--no-window-title", "--title"
    , unpack title, unpack duration ] >>= waitForProcess
  case exitCode of
    ExitFailure _ -> return ()
    ExitSuccess ->
      void $ proc "mpv" ["--really-quiet", "--volume=100", file] empty

I can press space bar to pause and resume timer in termdown which is an ncurses program.

crocket avatar Dec 23 '17 10:12 crocket

Yeah, I don't think you will be able to do this using the existing turtle utilities because they line-buffer input. You would need to use the underlying process library (like you did) for more fine-grained control

Gabriella439 avatar Dec 28 '17 18:12 Gabriella439