{-# LANGUAGE MultiWayIf #-}
module XMonad.Util.Loggers (
Logger
, aumixVolume
, battery
, date
, loadAvg
, maildirNew, maildirUnread
, logCmd , logFileCount
, logCurrent, logLayout
, logTitle, logTitles, logTitles'
, logConst, logDefault, (.|)
, logCurrentOnScreen, logLayoutOnScreen
, logTitleOnScreen, logWhenActive
, logTitlesOnScreen, logTitlesOnScreen'
, TitlesFormat(..)
, onLogger
, wrapL, fixedWidthL
, logSp, padL
, shortenL
, dzenColorL, xmobarColorL
) where
import XMonad (Default, gets, liftIO, Window)
import XMonad.Core
import qualified XMonad.StackSet as W
import XMonad.Hooks.StatusBar.PP
import XMonad.Hooks.UrgencyHook (readUrgents)
import XMonad.Util.Font (Align (..))
import XMonad.Util.NamedWindows (getName)
import Control.Exception as E
import XMonad.Prelude (find, fromMaybe, isPrefixOf, isSuffixOf, WindowScreen)
import Data.Time (defaultTimeLocale, formatTime, getCurrentTime)
import System.Directory (getDirectoryContents)
import System.IO (hGetLine)
import System.Process (runInteractiveCommand)
econst :: Monad m => a -> IOException -> m a
econst :: forall (m :: * -> *) a. Monad m => a -> IOException -> m a
econst = m a -> IOException -> m a
forall a b. a -> b -> a
const (m a -> IOException -> m a)
-> (a -> m a) -> a -> IOException -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
type Logger = X (Maybe String)
aumixVolume :: Logger
aumixVolume :: Logger
aumixVolume = String -> Logger
logCmd String
"aumix -vq"
battery :: Logger
battery :: Logger
battery = String -> Logger
logCmd String
"acpi | sed -r 's/.*?: (.*%).*/\\1/; s/[dD]ischarging, ([0-9]+%)/\\1-/; s/[cC]harging, ([0-9]+%)/\\1+/; s/[cC]harged, //'"
date :: String -> Logger
date :: String -> Logger
date String
fmt = IO (Maybe String) -> Logger
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Maybe String) -> Logger) -> IO (Maybe String) -> Logger
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> (UTCTime -> String) -> UTCTime -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
fmt (UTCTime -> Maybe String) -> IO UTCTime -> IO (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO UTCTime
getCurrentTime
loadAvg :: Logger
loadAvg :: Logger
loadAvg = String -> Logger
logCmd String
"uptime | sed 's/.*: //; s/,//g'"
logCmd :: String -> Logger
logCmd :: String -> Logger
logCmd String
c = IO (Maybe String) -> Logger
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Maybe String) -> Logger) -> IO (Maybe String) -> Logger
forall a b. (a -> b) -> a -> b
$ do (Handle
_, Handle
out, Handle
_, ProcessHandle
_) <- String -> IO (Handle, Handle, Handle, ProcessHandle)
runInteractiveCommand String
c
(String -> Maybe String) -> IO String -> IO (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Maybe String
forall a. a -> Maybe a
Just (Handle -> IO String
hGetLine Handle
out) IO (Maybe String)
-> (IOException -> IO (Maybe String)) -> IO (Maybe String)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch` Maybe String -> IOException -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> IOException -> m a
econst Maybe String
forall a. Maybe a
Nothing
logFileCount :: FilePath
-> (String -> Bool)
-> Logger
logFileCount :: String -> (String -> Bool) -> Logger
logFileCount String
d String -> Bool
p = do
[String]
c <- IO [String] -> X [String]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO ( String -> IO [String]
getDirectoryContents String
d)
let n :: Int
n = [String] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([String] -> Int) -> [String] -> Int
forall a b. (a -> b) -> a -> b
$ (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
Prelude.filter String -> Bool
p [String]
c
case Int
n of
Int
0 -> Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
Int
_ -> Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> Logger) -> Maybe String -> Logger
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show Int
n
maildirUnread :: FilePath -> Logger
maildirUnread :: String -> Logger
maildirUnread String
mdir = String -> (String -> Bool) -> Logger
logFileCount (String
mdir String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/cur/") (String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isSuffixOf String
",")
maildirNew :: FilePath -> Logger
maildirNew :: String -> Logger
maildirNew String
mdir = String -> (String -> Bool) -> Logger
logFileCount (String
mdir String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/new/") (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
".")
logTitle :: Logger
logTitle :: Logger
logTitle = (WindowSet -> Logger) -> Logger
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> Logger) -> Logger)
-> (WindowSet -> Logger) -> Logger
forall a b. (a -> b) -> a -> b
$ (Window -> X String) -> Maybe Window -> Logger
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((NamedWindow -> String) -> X NamedWindow -> X String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedWindow -> String
forall a. Show a => a -> String
show (X NamedWindow -> X String)
-> (Window -> X NamedWindow) -> Window -> X String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> X NamedWindow
getName) (Maybe Window -> Logger)
-> (WindowSet -> Maybe Window) -> WindowSet -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Maybe Window
forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek
logTitlesOnScreen
:: ScreenId
-> (String -> String)
-> (String -> String)
-> Logger
logTitlesOnScreen :: ScreenId -> (String -> String) -> (String -> String) -> Logger
logTitlesOnScreen ScreenId
sid String -> String
formatFoc String -> String
formatUnfoc =
ScreenId -> TitlesFormat -> Logger
logTitlesOnScreen' ScreenId
sid TitlesFormat :: (String -> String)
-> (String -> String) -> (String -> String) -> TitlesFormat
TitlesFormat{ focusedFormat :: String -> String
focusedFormat = String -> String
formatFoc
, unfocusedFormat :: String -> String
unfocusedFormat = String -> String
formatUnfoc
, urgentFormat :: String -> String
urgentFormat = String -> String
formatUnfoc
}
logTitlesOnScreen' :: ScreenId -> TitlesFormat -> Logger
logTitlesOnScreen' :: ScreenId -> TitlesFormat -> Logger
logTitlesOnScreen' ScreenId
sid (TitlesFormat String -> String
formatFoc String -> String
formatUnfoc String -> String
formatUrg) =
((WindowScreen -> Logger) -> ScreenId -> Logger
`withScreen` ScreenId
sid) ((WindowScreen -> Logger) -> Logger)
-> (WindowScreen -> Logger) -> Logger
forall a b. (a -> b) -> a -> b
$ \WindowScreen
screen -> do
let focWin :: Maybe Window
focWin = (Stack Window -> Window) -> Maybe (Stack Window) -> Maybe Window
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Stack Window -> Window
forall a. Stack a -> a
W.focus (Maybe (Stack Window) -> Maybe Window)
-> (WindowScreen -> Maybe (Stack Window))
-> WindowScreen
-> Maybe Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack (Workspace String (Layout Window) Window -> Maybe (Stack Window))
-> (WindowScreen -> Workspace String (Layout Window) Window)
-> WindowScreen
-> Maybe (Stack Window)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (WindowScreen -> Maybe Window) -> WindowScreen -> Maybe Window
forall a b. (a -> b) -> a -> b
$ WindowScreen
screen
[Window]
urgWins <- X [Window]
readUrgents
WindowScreen -> (Window -> String -> String) -> Logger
logTitlesOnScreenWorker WindowScreen
screen ((Window -> String -> String) -> Logger)
-> (Window -> String -> String) -> Logger
forall a b. (a -> b) -> a -> b
$ \Window
win String
name ->
if | Window -> Maybe Window
forall a. a -> Maybe a
Just Window
win Maybe Window -> Maybe Window -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Window
focWin -> String -> String
formatFoc String
name
| Window
win Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Window]
urgWins -> String -> String
formatUrg String
name
| Bool
otherwise -> String -> String
formatUnfoc String
name
logTitlesOnScreenWorker :: WindowScreen -> (Window -> String -> String) -> Logger
logTitlesOnScreenWorker :: WindowScreen -> (Window -> String -> String) -> Logger
logTitlesOnScreenWorker WindowScreen
screen Window -> String -> String
logger = do
let wins :: [Window]
wins = [Window]
-> (Stack Window -> [Window]) -> Maybe (Stack Window) -> [Window]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Stack Window -> [Window]
forall a. Stack a -> [a]
W.integrate (Maybe (Stack Window) -> [Window])
-> (WindowScreen -> Maybe (Stack Window))
-> WindowScreen
-> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack (Workspace String (Layout Window) Window -> Maybe (Stack Window))
-> (WindowScreen -> Workspace String (Layout Window) Window)
-> WindowScreen
-> Maybe (Stack Window)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (WindowScreen -> [Window]) -> WindowScreen -> [Window]
forall a b. (a -> b) -> a -> b
$ WindowScreen
screen
[String]
winNames <- (Window -> X String) -> [Window] -> X [String]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((NamedWindow -> String) -> X NamedWindow -> X String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedWindow -> String
forall a. Show a => a -> String
show (X NamedWindow -> X String)
-> (Window -> X NamedWindow) -> Window -> X String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> X NamedWindow
getName) [Window]
wins
Maybe String -> Logger
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe String -> Logger)
-> ([String] -> Maybe String) -> [String] -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> ([String] -> String) -> [String] -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unwords ([String] -> Logger) -> [String] -> Logger
forall a b. (a -> b) -> a -> b
$ (Window -> String -> String) -> [Window] -> [String] -> [String]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Window -> String -> String
logger [Window]
wins [String]
winNames
logTitles :: (String -> String) -> (String -> String) -> Logger
logTitles :: (String -> String) -> (String -> String) -> Logger
logTitles String -> String
formatFoc String -> String
formatUnfoc = do
ScreenId
sid <- (XState -> ScreenId) -> X ScreenId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> ScreenId) -> X ScreenId)
-> (XState -> ScreenId) -> X ScreenId
forall a b. (a -> b) -> a -> b
$ WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (WindowScreen -> ScreenId)
-> (XState -> WindowScreen) -> XState -> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> WindowScreen
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (WindowSet -> WindowScreen)
-> (XState -> WindowSet) -> XState -> WindowScreen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
ScreenId -> (String -> String) -> (String -> String) -> Logger
logTitlesOnScreen ScreenId
sid String -> String
formatFoc String -> String
formatUnfoc
logTitles' :: TitlesFormat -> Logger
logTitles' :: TitlesFormat -> Logger
logTitles' TitlesFormat
formatter =
(XState -> ScreenId) -> X ScreenId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (WindowScreen -> ScreenId)
-> (XState -> WindowScreen) -> XState -> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> WindowScreen
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (WindowSet -> WindowScreen)
-> (XState -> WindowSet) -> XState -> WindowScreen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset) X ScreenId -> (ScreenId -> Logger) -> Logger
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ScreenId -> TitlesFormat -> Logger
`logTitlesOnScreen'` TitlesFormat
formatter)
data TitlesFormat = TitlesFormat
{ TitlesFormat -> String -> String
focusedFormat :: String -> String
, TitlesFormat -> String -> String
unfocusedFormat :: String -> String
, TitlesFormat -> String -> String
urgentFormat :: String -> String
}
instance Default TitlesFormat where
def :: TitlesFormat
def = TitlesFormat :: (String -> String)
-> (String -> String) -> (String -> String) -> TitlesFormat
TitlesFormat
{ focusedFormat :: String -> String
focusedFormat = String -> String -> String -> String
wrap String
"[" String
"]" (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
xmobarRaw (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
shorten Int
30 (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
xmobarStrip
, unfocusedFormat :: String -> String
unfocusedFormat = String -> String
xmobarRaw (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
shorten Int
30 (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
xmobarStrip
, urgentFormat :: String -> String
urgentFormat = String -> String -> String -> String
wrap String
"!" String
"!" (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
xmobarRaw (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
shorten Int
30 (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
xmobarStrip
}
logLayout :: Logger
logLayout :: Logger
logLayout = (WindowSet -> Logger) -> Logger
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> Logger) -> Logger)
-> (WindowSet -> Logger) -> Logger
forall a b. (a -> b) -> a -> b
$ Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> Logger)
-> (WindowSet -> Maybe String) -> WindowSet -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> (WindowSet -> String) -> WindowSet -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> String
forall {i} {a} {sid} {sd}.
StackSet i (Layout Window) a sid sd -> String
ld
where ld :: StackSet i (Layout Window) a sid sd -> String
ld = Layout Window -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description (Layout Window -> String)
-> (StackSet i (Layout Window) a sid sd -> Layout Window)
-> StackSet i (Layout Window) a sid sd
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace i (Layout Window) a -> Layout Window
forall i l a. Workspace i l a -> l
W.layout (Workspace i (Layout Window) a -> Layout Window)
-> (StackSet i (Layout Window) a sid sd
-> Workspace i (Layout Window) a)
-> StackSet i (Layout Window) a sid sd
-> Layout Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen i (Layout Window) a sid sd -> Workspace i (Layout Window) a
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen i (Layout Window) a sid sd
-> Workspace i (Layout Window) a)
-> (StackSet i (Layout Window) a sid sd
-> Screen i (Layout Window) a sid sd)
-> StackSet i (Layout Window) a sid sd
-> Workspace i (Layout Window) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet i (Layout Window) a sid sd
-> Screen i (Layout Window) a sid sd
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current
logCurrent :: Logger
logCurrent :: Logger
logCurrent = (WindowSet -> Logger) -> Logger
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> Logger) -> Logger)
-> (WindowSet -> Logger) -> Logger
forall a b. (a -> b) -> a -> b
$ Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> Logger)
-> (WindowSet -> Maybe String) -> WindowSet -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> (WindowSet -> String) -> WindowSet -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> String
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag
logConst :: String -> Logger
logConst :: String -> Logger
logConst = Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> Logger)
-> (String -> Maybe String) -> String -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
forall a. a -> Maybe a
Just
logDefault :: Logger -> Logger -> Logger
logDefault :: Logger -> Logger -> Logger
logDefault Logger
l Logger
d = Logger
l Logger -> (Maybe String -> Logger) -> Logger
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Logger -> (String -> Logger) -> Maybe String -> Logger
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Logger
d String -> Logger
logConst
(.|) :: Logger -> Logger -> Logger
.| :: Logger -> Logger -> Logger
(.|) = Logger -> Logger -> Logger
logDefault
logWhenActive :: ScreenId -> Logger -> Logger
logWhenActive :: ScreenId -> Logger -> Logger
logWhenActive ScreenId
n Logger
l = do
ScreenId
c <- (WindowSet -> X ScreenId) -> X ScreenId
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X ScreenId) -> X ScreenId)
-> (WindowSet -> X ScreenId) -> X ScreenId
forall a b. (a -> b) -> a -> b
$ ScreenId -> X ScreenId
forall (m :: * -> *) a. Monad m => a -> m a
return (ScreenId -> X ScreenId)
-> (WindowSet -> ScreenId) -> WindowSet -> X ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (WindowScreen -> ScreenId)
-> (WindowSet -> WindowScreen) -> WindowSet -> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> WindowScreen
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current
if ScreenId
n ScreenId -> ScreenId -> Bool
forall a. Eq a => a -> a -> Bool
== ScreenId
c then Logger
l else Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
logTitleOnScreen :: ScreenId -> Logger
logTitleOnScreen :: ScreenId -> Logger
logTitleOnScreen =
(WindowScreen -> Logger) -> ScreenId -> Logger
withScreen
((WindowScreen -> Logger) -> ScreenId -> Logger)
-> (WindowScreen -> Logger) -> ScreenId -> Logger
forall a b. (a -> b) -> a -> b
$ (Window -> X String) -> Maybe Window -> Logger
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((NamedWindow -> String) -> X NamedWindow -> X String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedWindow -> String
forall a. Show a => a -> String
show (X NamedWindow -> X String)
-> (Window -> X NamedWindow) -> Window -> X String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> X NamedWindow
getName)
(Maybe Window -> Logger)
-> (WindowScreen -> Maybe Window) -> WindowScreen -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Window
forall a. Stack a -> a
W.focus (Stack Window -> Window) -> Maybe (Stack Window) -> Maybe Window
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)
(Maybe (Stack Window) -> Maybe Window)
-> (WindowScreen -> Maybe (Stack Window))
-> WindowScreen
-> Maybe Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack
(Workspace String (Layout Window) Window -> Maybe (Stack Window))
-> (WindowScreen -> Workspace String (Layout Window) Window)
-> WindowScreen
-> Maybe (Stack Window)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace
logCurrentOnScreen :: ScreenId -> Logger
logCurrentOnScreen :: ScreenId -> Logger
logCurrentOnScreen = (WindowScreen -> Logger) -> ScreenId -> Logger
withScreen ((WindowScreen -> Logger) -> ScreenId -> Logger)
-> (WindowScreen -> Logger) -> ScreenId -> Logger
forall a b. (a -> b) -> a -> b
$ String -> Logger
logConst (String -> Logger)
-> (WindowScreen -> String) -> WindowScreen -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> String
forall i l a. Workspace i l a -> i
W.tag (Workspace String (Layout Window) Window -> String)
-> (WindowScreen -> Workspace String (Layout Window) Window)
-> WindowScreen
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace
logLayoutOnScreen :: ScreenId -> Logger
logLayoutOnScreen :: ScreenId -> Logger
logLayoutOnScreen =
(WindowScreen -> Logger) -> ScreenId -> Logger
withScreen ((WindowScreen -> Logger) -> ScreenId -> Logger)
-> (WindowScreen -> Logger) -> ScreenId -> Logger
forall a b. (a -> b) -> a -> b
$ String -> Logger
logConst (String -> Logger)
-> (WindowScreen -> String) -> WindowScreen -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Layout Window -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description (Layout Window -> String)
-> (WindowScreen -> Layout Window) -> WindowScreen -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Layout Window
forall i l a. Workspace i l a -> l
W.layout (Workspace String (Layout Window) Window -> Layout Window)
-> (WindowScreen -> Workspace String (Layout Window) Window)
-> WindowScreen
-> Layout Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace
withScreen :: (WindowScreen -> Logger) -> ScreenId -> Logger
withScreen :: (WindowScreen -> Logger) -> ScreenId -> Logger
withScreen WindowScreen -> Logger
f ScreenId
n = do
[WindowScreen]
ss <- (WindowSet -> X [WindowScreen]) -> X [WindowScreen]
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X [WindowScreen]) -> X [WindowScreen])
-> (WindowSet -> X [WindowScreen]) -> X [WindowScreen]
forall a b. (a -> b) -> a -> b
$ [WindowScreen] -> X [WindowScreen]
forall (m :: * -> *) a. Monad m => a -> m a
return ([WindowScreen] -> X [WindowScreen])
-> (WindowSet -> [WindowScreen]) -> WindowSet -> X [WindowScreen]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> [WindowScreen]
forall i l a s sd. StackSet i l a s sd -> [Screen i l a s sd]
W.screens
case (WindowScreen -> Bool) -> [WindowScreen] -> Maybe WindowScreen
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((ScreenId -> ScreenId -> Bool
forall a. Eq a => a -> a -> Bool
== ScreenId
n) (ScreenId -> Bool)
-> (WindowScreen -> ScreenId) -> WindowScreen -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen) [WindowScreen]
ss of
Just WindowScreen
s -> WindowScreen -> Logger
f WindowScreen
s
Maybe WindowScreen
Nothing -> Maybe String -> Logger
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe String
forall a. Maybe a
Nothing
onLogger :: (String -> String) -> Logger -> Logger
onLogger :: (String -> String) -> Logger -> Logger
onLogger = (Maybe String -> Maybe String) -> Logger -> Logger
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe String -> Maybe String) -> Logger -> Logger)
-> ((String -> String) -> Maybe String -> Maybe String)
-> (String -> String)
-> Logger
-> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String) -> Maybe String -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
wrapL :: String -> String -> Logger -> Logger
wrapL :: String -> String -> Logger -> Logger
wrapL String
l String
r = (String -> String) -> Logger -> Logger
onLogger ((String -> String) -> Logger -> Logger)
-> (String -> String) -> Logger -> Logger
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> String
wrap String
l String
r
fixedWidthL :: Align
-> String
-> Int
-> Logger -> Logger
fixedWidthL :: Align -> String -> Int -> Logger -> Logger
fixedWidthL Align
a String
str Int
n Logger
logger = do
Maybe String
mbl <- Logger
logger
let l :: String
l = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
"" Maybe String
mbl
case Align
a of
Align
AlignCenter -> String -> Logger
forall {a}. a -> X (Maybe a)
toL (Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
n (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
forall {t :: * -> *} {a}. Foldable t => t a -> String
padhalf String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
cs)
Align
AlignRight -> String -> Logger
forall {a}. a -> X (Maybe a)
toL (String -> String
forall a. [a] -> [a]
reverse (Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
n (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
reverse String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
cs))
Align
_ -> String -> Logger
forall {a}. a -> X (Maybe a)
toL (Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
n (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
cs)
where
toL :: a -> X (Maybe a)
toL = Maybe a -> X (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> X (Maybe a)) -> (a -> Maybe a) -> a -> X (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just
cs :: String
cs = String -> String
forall a. [a] -> [a]
cycle String
str
padhalf :: t a -> String
padhalf t a
x = String -> String
forall a. [a] -> [a]
reverse (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
take ((Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length t a
x) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2) String
cs
logSp :: Int -> Logger
logSp :: Int -> Logger
logSp Int
n = Maybe String -> Logger
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> Logger)
-> (String -> Maybe String) -> String -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String)
-> (String -> String) -> String -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
n (String -> Logger) -> String -> Logger
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
cycle String
" "
padL :: Logger -> Logger
padL :: Logger -> Logger
padL = (String -> String) -> Logger -> Logger
onLogger String -> String
pad
shortenL :: Int -> Logger -> Logger
shortenL :: Int -> Logger -> Logger
shortenL = (String -> String) -> Logger -> Logger
onLogger ((String -> String) -> Logger -> Logger)
-> (Int -> String -> String) -> Int -> Logger -> Logger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
shorten
dzenColorL :: String -> String -> Logger -> Logger
dzenColorL :: String -> String -> Logger -> Logger
dzenColorL String
fg String
bg = (String -> String) -> Logger -> Logger
onLogger ((String -> String) -> Logger -> Logger)
-> (String -> String) -> Logger -> Logger
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> String
dzenColor String
fg String
bg
xmobarColorL :: String -> String -> Logger -> Logger
xmobarColorL :: String -> String -> Logger -> Logger
xmobarColorL String
fg String
bg = (String -> String) -> Logger -> Logger
onLogger ((String -> String) -> Logger -> Logger)
-> (String -> String) -> Logger -> Logger
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> String
xmobarColor String
fg String
bg