summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Command.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-01-28 03:21:26 +0000
committerjao <jao@gnu.org>2022-01-29 06:42:29 +0000
commitf3cf53bad93d290130a13cf4e56df54b51d5c174 (patch)
treed3c934b9e097b19d826938e0050309f8a0b2a333 /src/Xmobar/Plugins/Command.hs
parenta5c35003c88c4b050e56cfb5d93a0e0d77d9c223 (diff)
downloadxmobar-f3cf53bad93d290130a13cf4e56df54b51d5c174.tar.gz
xmobar-f3cf53bad93d290130a13cf4e56df54b51d5c174.tar.bz2
Xmobar.Run.Command -> Xmobar.Plugins.Command
Diffstat (limited to 'src/Xmobar/Plugins/Command.hs')
-rw-r--r--src/Xmobar/Plugins/Command.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Command.hs b/src/Xmobar/Plugins/Command.hs
new file mode 100644
index 0000000..d63f56c
--- /dev/null
+++ b/src/Xmobar/Plugins/Command.hs
@@ -0,0 +1,54 @@
+------------------------------------------------------------------------------
+-- |
+-- Module: Xmobar.Plugins.Command
+-- Copyright: (c) 2018, 2022 Jose Antonio Ortega Ruiz
+-- License: BSD3-style (see LICENSE)
+--
+-- Maintainer: jao@gnu.org
+-- Stability: unstable
+-- Portability: portable
+-- Created: Sun Dec 02, 2018 05:29
+--
+--
+-- The basic Command plugin
+--
+------------------------------------------------------------------------------
+
+
+module Xmobar.Plugins.Command where
+
+import Control.Exception (handle, SomeException(..))
+import System.Process
+import System.Exit
+import System.IO (hClose, hGetLine)
+
+import Xmobar.Run.Exec
+
+data Command = Com Program Args Alias Rate
+ | ComX Program Args String Alias Rate
+ deriving (Show,Read,Eq)
+
+type Args = [String]
+type Program = String
+type Alias = String
+type Rate = Int
+
+instance Exec Command where
+ alias (ComX p _ _ a _) =
+ if p /= "" then (if a == "" then p else a) else ""
+ alias (Com p a al r) = alias (ComX p a "" al r)
+ start (Com p as al r) cb =
+ start (ComX p as ("Could not execute command " ++ p) al r) cb
+ start (ComX prog args msg _ r) cb = if r > 0 then go else exec
+ where go = doEveryTenthSeconds r exec
+ exec = do
+ (i,o,e,p) <- runInteractiveProcess prog args Nothing Nothing
+ exit <- waitForProcess p
+ let closeHandles = hClose o >> hClose i >> hClose e
+ getL = handle (\(SomeException _) -> return "")
+ (hGetLine o)
+ case exit of
+ ExitSuccess -> do str <- getL
+ closeHandles
+ cb str
+ _ -> closeHandles >> cb msg