summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--news.md4
-rw-r--r--readme.md16
-rw-r--r--src/Plugins/StdinReader.hs21
3 files changed, 35 insertions, 6 deletions
diff --git a/news.md b/news.md
index 9db2984..28c3335 100644
--- a/news.md
+++ b/news.md
@@ -10,6 +10,9 @@ _New features_
[github #99]).
- `Com` uses safer `runInteractiveProcess` instead of spawning a
shell (David McLean).
+ - New plugin `UnsafeStdinReader` that allows actions from stdin.
+ Now it's possible to have clickable workspaces!
+ (see [github #125]).
_Bug fixes_
@@ -23,6 +26,7 @@ _Bug fixes_
[github #99]: https://github.com/jaor/xmobar/issues/115
[github #115]: https://github.com/jaor/xmobar/issues/115
[github #117]: https://github.com/jaor/xmobar/issues/117
+[github #125]: https://github.com/jaor/xmobar/issues/125
[issue #65]: http://code.google.com/p/xmobar/issues/detail?id=65
## Version 0.18 (June 5, 2013)
diff --git a/readme.md b/readme.md
index 26c00af..89eea29 100644
--- a/readme.md
+++ b/readme.md
@@ -1117,6 +1117,22 @@ can be used in the output template as `%mydate%`
- Aliases to StdinReader
- Displays any text received by xmobar on its standard input.
+- Strips actions from the text received. This means you can't pass dynamic
+ actions via stdin. This is safer than `UnsafeStdinReader` because there is
+ no need to escape the content before passing it to xmobar's standard input.
+
+`UnsafeStdinReader`
+
+- Aliases to UnsafeStdinReader
+- Displays any text received by xmobar on its standard input.
+- Will not do anything to the text received. This means you can pass dynamic
+ actions via stdin. Be careful to remove tags from dynamic text that you
+ pipe-thru to xmobar's standard input, e.g. window's title. There is no way
+ to escape the tags, i.e. you can't print a literal "<action>" tag on xmobar.
+- Sample usage: send to xmobar's stdin the list of your workspaces enclosed by
+ actions tags that switches the workspaces to be able to switch workspaces by
+ clicking on xmobar:
+ `<action=xdotool key alt+1>ws1</action> <action=xdotool key alt+1>ws2</action>`
`Date Format Alias RefreshRate`
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