@hackage reflex-process0.3.3.1

Reflex FRP interface for running system processes

reflex-process

Haskell Hackage BSD3 License

Functional-reactive system processes

Run and interact with system processes from within a Reflex FRP application.

Example

The following example uses reflex-vty to run a terminal application that calls a shell command and displays the result:

> {-# LANGUAGE OverloadedStrings #-}
> import Reflex
> import Reflex.Process
> import Reflex.Vty
>
> import Control.Monad ((<=<))
> import Data.Default (def)
> import qualified Data.Set as Set
> import qualified Data.Text as T
> import qualified Data.Text.Encoding as T
> import qualified Graphics.Vty.Input as V
> import qualified System.Process as P
>
> cmd :: P.CreateProcess
> cmd = P.proc "ls" ["-a"]
>
> main :: IO ()
> main = mainWidget $ initManager_ $ col $ do
>   exit <- keyCombos $ Set.singleton (V.KChar 'c', [V.MCtrl])
>   p <- createProcess cmd def
>   stdout <- foldDyn (flip mappend) "" $ _process_stdout p
>   grout flex $ boxStatic def $ col $ do
>     grout (fixed 3) $ boxStatic def $ text "reflex-process"
>     grout (fixed 3) $ text "Press Ctrl-C to exit."
>     grout (fixed 2) $ text $ pure $ "Running command: " <> case P.cmdspec cmd of
>       P.ShellCommand s -> T.pack s
>       P.RawCommand p args -> T.intercalate " " $ T.pack <$> (p : args)
>     grout (fixed 1) $ text "stdout:"
>     grout flex $ text $ T.decodeUtf8 <$> current stdout
>   pure $ () <$ exit

Developer environment

You can get ghcid running for working on the code with the command:

nix-shell -E '((import ./reflex-platform {}).ghc.callCabal2nix "reflex-process" ./. {}).env' --run ghcid