summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorThiago Negri <evohunz@gmail.com>2013-09-10 17:57:16 -0300
committerThiago Negri <evohunz@gmail.com>2013-09-11 22:05:12 -0300
commitb780acaeac9545199867405f6c14434e77baf1d7 (patch)
tree12d9b3402c049c21a139bcf8e9c51a5ce5f3e593 /src/Plugins
parent1d20b99ec742ce08a8083a01ccb15adb763815e1 (diff)
downloadxmobar-b780acaeac9545199867405f6c14434e77baf1d7.tar.gz
xmobar-b780acaeac9545199867405f6c14434e77baf1d7.tar.bz2
Created UnsafeStdinReader plugin
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/StdinReader.hs21
1 files changed, 15 insertions, 6 deletions
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