diff options
author | jao <jao@gnu.org> | 2018-12-02 05:50:56 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-12-02 05:50:56 +0000 |
commit | 6fc4f0cfcb809b51048e6a3d952b9c887e07b13b (patch) | |
tree | 1af7295e8ba7f675d4cde30e34bcc91a79692a54 /src/Xmobar/Run/Exec.hs | |
parent | 453ad68e5b24a6dd3a2aaba8727dc6c5c0bdfc9e (diff) | |
download | xmobar-6fc4f0cfcb809b51048e6a3d952b9c887e07b13b.tar.gz xmobar-6fc4f0cfcb809b51048e6a3d952b9c887e07b13b.tar.bz2 |
Fix: exposing the Command constructors in lib
Diffstat (limited to 'src/Xmobar/Run/Exec.hs')
-rw-r--r-- | src/Xmobar/Run/Exec.hs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Xmobar/Run/Exec.hs b/src/Xmobar/Run/Exec.hs new file mode 100644 index 0000000..c8fcb9e --- /dev/null +++ b/src/Xmobar/Run/Exec.hs @@ -0,0 +1,48 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Xmobar.Exec +-- Copyright : (c) Andrea Rossato +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org> +-- Stability : unstable +-- Portability : unportable +-- +-- The 'Exec' class and the 'Command' data type. +-- +-- The 'Exec' class rappresents the executable types, whose constructors may +-- appear in the 'Config.commands' field of the 'Config.Config' data type. +-- +-- The 'Command' data type is for OS commands to be run by xmobar +-- +----------------------------------------------------------------------------- + +module Xmobar.Run.Exec (Exec (..), tenthSeconds) where + +import Prelude +import Data.Char +import Control.Concurrent + +import Xmobar.System.Signal + +-- | Work around to the Int max bound: since threadDelay takes an Int, it +-- is not possible to set a thread delay grater than about 45 minutes. +-- With a little recursion we solve the problem. +tenthSeconds :: Int -> IO () +tenthSeconds s | s >= x = do threadDelay (x * 100000) + tenthSeconds (s - x) + | otherwise = threadDelay (s * 100000) + where x = (maxBound :: Int) `div` 100000 + +class Show e => Exec e where + alias :: e -> String + alias e = takeWhile (not . isSpace) $ show e + rate :: e -> Int + rate _ = 10 + run :: e -> IO String + run _ = return "" + start :: e -> (String -> IO ()) -> IO () + start e cb = go + where go = run e >>= cb >> tenthSeconds (rate e) >> go + trigger :: e -> (Maybe SignalType -> IO ()) -> IO () + trigger _ sh = sh Nothing |