-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Utilities for creating inputs for dzen. -- -- This library has everything you need to create your dzen's -- bar input strings using powerful combinators in a type-safe way. -- -- It can be used to create standalone "scripts" with runhaskell -- or it can be used inside xmonad's main function. -- -- To see what can be done, please read the documentation of the toplevel -- module System.Dzen. @package dzen-utils @version 0.1 -- | This module contains most of the basic functions of this package. The -- data types presented here are: -- --
-- pA1 +-+ pB +<+ pC +<+ pD +/+ pA2 :: Printer (a,(b,(c,d))) ---- -- where both pA1 and pA2 are of type Printer -- a. (+<+) :: Printer a -> Printer (b, c) -> Printer (b, (a, c)) -- | This is a general combine function for Printers. The outputs -- are always concatenated, but the inputs are given by the supplied -- function. -- -- The combining operators above are defined as: -- --
-- (+++) = combine id -- restricted to Printers -- (+=+) = combine (\x -> ( x, x)) -- (+-+) = combine (\x -> (fst x, x)) -- (+/+) = combine (\(a,b) -> (b,a)) -- (+<+) = combine (\(b,(a,c)) -> (a,(b,c))) ---- -- Note also the resamblence with comap. In fact, if we have -- (+++) and comap we may define -- --
-- combine f a b = comap f (a +++ b) -- pointwise -- combine = flip (.) (+++) . (.) . comap -- pointfree ---- -- and with combine and simple we may define -- --
-- comap f = combine (\i -> ((), f i)) (simple $ const mempty) -- pointwise -- comap = flip combine (simple $ const mempty) . ((,) () .) -- pointfree --combine :: (c -> (a, b)) -> Printer a -> Printer b -> Printer c -- | Apply a printer to an appropriate input, returning the output string -- and the new printer. apply :: Printer a -> a -> (String, Printer a) -- | Apply a printer many times in sequence. Most of the time you would -- ignore the final printer using applyMany_, but it can be used -- to continue applying. applyMany :: Printer a -> [a] -> ([String], Printer a) -- | Like applyMany but ignoring the final printer. applyMany_ :: Printer a -> [a] -> [String] -- | Apply a printer forever inside a monad. The first action is used as a -- supply of inputs while the second action receives the output before -- the next input is requested. -- -- Note that your supply may be anything. For example, inside IO -- you may use threadDelay: -- --
-- applyForever (threadDelay 100000 >> getInfo) (hPutStrLn dzenHandle) --applyForever :: Monad m => Printer a -> m a -> (String -> m ()) -> m () -- | Transform is a specialization of Functor for -- DStrings. This class is used for functions that may receive -- DString or Printer a as an argument because they -- operate only on their outputs and internal states (and not on the -- inputs). -- -- So, whenever you see a function of type -- --
-- func :: Transform a => Blah -> Bleh -> a -> a ---- -- it means that func can be used in two ways: -- --
-- func :: Blah -> Bleh -> DString -> DString -- func :: Blah -> Bleh -> Printer a -> Printer a -- Printer of any input! ---- -- Try to have this in mind when reading the types. -- -- Note: There is also a non-exported transformSt for -- transforming the state in this class, otherwise it would be -- meaningless to use a class only for transform (it would be -- better to make liftT :: (DString -> DString) -> (Printer a -- -> Printer a)). class Transform a transform :: Transform a => (DString -> DString) -> (a -> a) instance Combine (Printer a) (Printer b) instance Combine (Printer a) DString instance Combine DString (Printer a) instance Combine DString DString -- | Support for colours. This module is entirely based on the -- colour package, so we strongly recommend that you at least -- --
-- import qualified Data.Colour.Names as C ---- -- which will import various aliases for creating Colours. -- -- Note changing the colours using the functions below do not hinder the -- use of automatic padding. module System.Dzen.Colour -- | Our colours. type DColour = Colour Double -- | Set the foreground colour. Note that the foreground colour is changed -- only inside the transformed DString or Printer, -- unlike using "^fg" which may affect subsequent strings. -- -- So you may write fg black (fg lime (str "lime") -- +++ str "black") and it works like you expect it to. fg :: Transform a => DColour -> (a -> a) -- | Like fg, but set the background colour. bg :: Transform a => DColour -> (a -> a) -- | Set the foreground colour to be the default one, which is specified as -- a parameter to dzen (outside the control of the printers). defFg :: Transform a => a -> a -- | Like defFg, but for the background colour. defBg :: Transform a => a -> a -- | Set the foreground to be a specified one (Just c) or the -- dzen's default (Nothing). Both fg and defFg are -- specializations of this function. changeFg :: Transform a => Maybe DColour -> (a -> a) -- | Like changeFg, but for the background colour. changeBg :: Transform a => Maybe DColour -> (a -> a) -- | Support for the graphical abilities of dzen. Unfortunately -- this is not the strongest are of dzen, so there isn't a lot -- of functionality here, but there are "bindings" for every function -- they provide. -- -- You can draw: -- --
-- " 123" -- if padding on the left -- "123 " -- if padding on the right -- " 123 " -- if padding on both sides ---- -- We provide two kinds of padding here: -- --
-- 96% [==================> ] --module System.Dzen.Bars -- | Mimics the dbar utility. Uses the dbar_style. dbar :: (Num a, Enum a, Ord a) => Bool -> Width -> (a, a) -> a -> DString -- | Mimics the dbar utility while getting the input dinamically. cdbar :: (Num a, Enum a, Ord a) => Bool -> Width -> (a, a) -> Printer a -- | Mimics the gdbar utility. Uses the gdbar_style. gdbar :: (Num a, Enum a, Ord a) => Bool -> (Width, Height) -> Maybe DColour -> Maybe DColour -> Bool -> (a, a) -> a -> DString -- | Mimics the gdbar utility while getting the input dinamically. cgdbar :: (Num a, Enum a, Ord a) => Bool -> (Width, Height) -> Maybe DColour -> Maybe DColour -> Bool -> (a, a) -> Printer a -- | Draws a bar and optionally some text describing some quantity in -- relation to some range. For example, -- --
-- bar (AtLeft Percentage) (Text "[" "=" (Just ">") " " "]" 20) (-10,10) i ---- -- produces the bars -- --
-- " 2% [ ]" where i = -9.6 -- " 2% [> ]" where i = -9.5 -- " 50% [=========> ]" where i = 0 -- " 96% [==================> ]" where i = 9.4 -- " 99% [===================>]" where i = 9.99 -- "100% [====================]" where i = 10 ---- -- Note that the text is always padded to four characters. If the first -- bar above had AtRight Percentage the result would be -- --
-- "[ ] 2% " ---- -- so the padding always inserts the spaces on the outside. bar :: (Num a, Enum a, Ord a) => BarText -> BarType -> (a, a) -> a -> DString -- | bar wrapped with simple so that the value is taken from -- an input. cbar :: (Num a, Enum a, Ord a) => BarText -> BarType -> (a, a) -> Printer a -- | The type of the bar to be drawn. data BarType -- | Draws a text bar. Note, however, that the DStrings below can -- be anything, not just text. For example, they may have colours -- (fg), shapes (rects and circs) or icons, -- you may even simulate both Filled and Hollow using just -- Text (although performance would be suboptimal). Text :: !DString -> !DString -> !Maybe DString -> !DString -> !DString -> !Width -> BarType -- | Text written at the start. txtOpen :: BarType -> !DString -- | Text written for each filled square. txtFilled :: BarType -> !DString -- | Text written for the last filled square. If Nothing, the same -- as the filled square is used, but more fairly than if you used the -- same value for filled and middle chars. txtMiddle :: BarType -> !Maybe DString -- | Text written for the unfilled squares. txtBackground :: BarType -> !DString -- | Text written at the end. txtClose :: BarType -> !DString -- | How many squares there should be (i.e. does not count the open and -- close parts). txtWidth :: BarType -> !Width -- | Draws a filled graphical bar, like gdbar would. Filled :: !Maybe DColour -> !Maybe DColour -> !(Width, Height) -> BarType -- | Colour used for filled squares, or Nothing to use the default -- foreground colour. grpFilled :: BarType -> !Maybe DColour -- | Colour used for the unfilled squares, or Nothing to use the -- default background colour. grpBackground :: BarType -> !Maybe DColour -- | Size of the whole bar. grpSize :: BarType -> !(Width, Height) -- | Draws a filled graphical bar with a surrounding border. Hollow :: !Maybe DColour -> !Maybe DColour -> !Maybe DColour -> !(Width, Height) -> BarType -- | Colour used for filled squares, or Nothing to use the default -- foreground colour. grpFilled :: BarType -> !Maybe DColour -- | Colour used for the unfilled squares, or Nothing to use the -- default background colour. grpBackground :: BarType -> !Maybe DColour -- | Colour of the border, or Nothing to use the default -- foreground colour. grpBorder :: BarType -> !Maybe DColour -- | Size of the whole bar. grpSize :: BarType -> !(Width, Height) -- | The type of text to be written. data BarTextType Percentage :: BarTextType Absolute :: BarTextType -- | How to draw the bar text. AtLeft and AtRight are -- used to specify if the text is at the left or the right of the bar, -- and None means that no text will be written. data BarText AtLeft :: !BarTextType -> BarText AtRight :: !BarTextType -> BarText None :: BarText -- | The style produced by the dbar utility. dbar_style :: Char -> Width -> BarType -- | The style of gdbar (or something very close). gdbar_style :: (Width, Height) -> Maybe DColour -> Maybe DColour -> Bool -> BarType instance Eq BarText instance Ord BarText instance Show BarText instance Eq BarTextType instance Ord BarTextType instance Show BarTextType instance Enum BarTextType instance Show BarType -- | Functions for creating supplies and running dzen. module System.Dzen.Process -- | Pipes a Printer to a fresh instance of dzen. It runs -- the following commands: -- --
-- prA :: Printer a -- prB :: Printer b -- prC :: Printer c ---- -- and supply functions -- --
-- getA :: m a -- getB :: m b -- getC :: m c ---- -- for some monad m. The final printer -- --
-- prFinal = prA +++ prB +++ prC ---- -- will be of type Printer (a,(b,c)), so you may use as its -- supply function -- --
-- getFinal = getA ## getB ## getC ---- -- which is of type m (a,(b,c)). (##) :: Monad m => m a -> m b -> m (a, b) -- | Runs a dzen instance and returns its stdin pipe. -- Both stdout and stderr of the new process will be -- the same as this process'. The pipe returned is already line buffered. -- -- The first string is interpreted as a shell command to start -- dzen. Some examples of usage: -- --
-- createDzen (RawCommand "dzen2" ["-p"]) -- createDzen (ShellCommand "dzen2 -l 8 -bg #331100") --createDzen :: CmdSpec -> IO Handle -- | Like createDzen, but never uses a shell (which is good). createDzen' :: FilePath -> [String] -> IO Handle -- | Hello! -- -- This is dzen-utils' main module. It re-exports every other -- module from this library, so you may just say -- --
-- import System.Dzen ---- -- and you'll have everything in hand. To learn more about this library, -- please see the documentation of each module exported here. To get you -- started, there are some simple examples below. :) module System.Dzen