summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Run/Command.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-12-02 05:50:56 +0000
committerjao <jao@gnu.org>2018-12-02 05:50:56 +0000
commit6fc4f0cfcb809b51048e6a3d952b9c887e07b13b (patch)
tree1af7295e8ba7f675d4cde30e34bcc91a79692a54 /src/Xmobar/Run/Command.hs
parent453ad68e5b24a6dd3a2aaba8727dc6c5c0bdfc9e (diff)
downloadxmobar-6fc4f0cfcb809b51048e6a3d952b9c887e07b13b.tar.gz
xmobar-6fc4f0cfcb809b51048e6a3d952b9c887e07b13b.tar.bz2
Fix: exposing the Command constructors in lib
Diffstat (limited to 'src/Xmobar/Run/Command.hs')
-rw-r--r--src/Xmobar/Run/Command.hs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Xmobar/Run/Command.hs b/src/Xmobar/Run/Command.hs
new file mode 100644
index 0000000..0953132
--- /dev/null
+++ b/src/Xmobar/Run/Command.hs
@@ -0,0 +1,55 @@
+------------------------------------------------------------------------------
+-- |
+-- Module: Xmobar.Plugins.Command
+-- Copyright: (c) 2018 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.Run.Command where
+
+import Control.Exception (handle, SomeException(..))
+import System.Process
+import System.Exit
+import System.IO (hClose)
+import Xmobar.System.Utils (hGetLineSafe)
+
+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 = exec >> tenthSeconds r >> go
+ 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 "")
+ (hGetLineSafe o)
+ case exit of
+ ExitSuccess -> do str <- getL
+ closeHandles
+ cb str
+ _ -> closeHandles >> cb msg