-----------------------------------------------------------------------------
-- |
-- 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 represents 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, doEveryTenthSeconds) where

import Prelude
import Data.Char

import Xmobar.App.Timer (doEveryTenthSeconds, tenthSeconds)
import Xmobar.System.Signal

class Show e => Exec e where
    alias   :: e -> String
    alias   e
e    = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ e -> String
forall a. Show a => a -> String
show e
e
    rate    :: e -> Int
    rate    e
_    = Int
10
    run     :: e -> IO String
    run     e
_    = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
    start   :: e -> (String -> IO ()) -> IO ()
    start   e
e String -> IO ()
cb = IO ()
go
        where go :: IO ()
go = Int -> IO () -> IO ()
doEveryTenthSeconds (e -> Int
forall e. Exec e => e -> Int
rate e
e) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ e -> IO String
forall e. Exec e => e -> IO String
run e
e IO String -> (String -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> IO ()
cb
    trigger :: e -> (Maybe SignalType -> IO ()) -> IO ()
    trigger e
_ Maybe SignalType -> IO ()
sh  = Maybe SignalType -> IO ()
sh Maybe SignalType
forall a. Maybe a
Nothing