From b780acaeac9545199867405f6c14434e77baf1d7 Mon Sep 17 00:00:00 2001 From: Thiago Negri Date: Tue, 10 Sep 2013 17:57:16 -0300 Subject: Created UnsafeStdinReader plugin --- src/Plugins/StdinReader.hs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Plugins/StdinReader.hs b/src/Plugins/StdinReader.hs index f242f93..35f0375 100644 --- a/src/Plugins/StdinReader.hs +++ b/src/Plugins/StdinReader.hs @@ -8,11 +8,15 @@ -- Stability : unstable -- Portability : unportable -- --- A plugin for reading from stdin +-- A plugin for reading from `stdin`. +-- +-- Exports: +-- - `StdinReader` to safely display stdin content (striping actions). +-- - `UnsafeStdinReader` to display stdin content as-is. -- ----------------------------------------------------------------------------- -module Plugins.StdinReader where +module Plugins.StdinReader (StdinReader(..)) where import Prelude import System.Posix.Process @@ -22,14 +26,19 @@ import Control.Exception (SomeException(..), handle) import Plugins import Actions (stripActions) -data StdinReader = StdinReader deriving (Read, Show) +data StdinReader = StdinReader | UnsafeStdinReader + deriving (Read, Show) instance Exec StdinReader where - start StdinReader cb = do + start stdinReader cb = do s <- handle (\(SomeException e) -> do hPrint stderr e; return "") (hGetLineSafe stdin) - cb (stripActions s) + cb $ escape stdinReader s eof <- hIsEOF stdin if eof then exitImmediately ExitSuccess - else start StdinReader cb + else start stdinReader cb + +escape :: StdinReader -> String -> String +escape StdinReader = stripActions +escape UnsafeStdinReader = id -- cgit v1.2.3