From ee9be16599f20aef6d1d3fd15666c00452f85aba Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 21 Nov 2022 12:05:03 -0700 Subject: Format with ormolu. --- src/Rahm/Desktop/XMobarLog.hs | 119 ++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 61 deletions(-) (limited to 'src/Rahm/Desktop/XMobarLog.hs') diff --git a/src/Rahm/Desktop/XMobarLog.hs b/src/Rahm/Desktop/XMobarLog.hs index e419739..5969044 100644 --- a/src/Rahm/Desktop/XMobarLog.hs +++ b/src/Rahm/Desktop/XMobarLog.hs @@ -1,24 +1,23 @@ -module Rahm.Desktop.XMobarLog ( XMobarLog, spawnXMobar, xMobarLogHook ) where +module Rahm.Desktop.XMobarLog (XMobarLog, spawnXMobar, xMobarLogHook) where import Control.Arrow (second) import Control.Monad (forM_) -import Control.Monad.Writer (tell, execWriter) +import Control.Monad.Writer (execWriter, tell) +import Data.Char (isAsciiLower, isAsciiUpper, isDigit) import Data.List (sortBy) -import Data.Maybe (mapMaybe, isJust) +import Data.Maybe (isJust, mapMaybe) import Data.Ord (comparing) -import Data.Char (isAsciiLower, isAsciiUpper, isDigit) import Rahm.Desktop.Layout.Draw (drawLayout) -import System.IO (Handle, hSetEncoding, hPutStrLn, utf8) -import XMonad.Util.NamedWindows (getName) -import XMonad.Util.Run (spawnPipe) -import XMonad (X) -import Rahm.Desktop.Workspaces (getPopulatedWorkspaces, WorkspaceState(..)) -import Text.Printf import Rahm.Desktop.Logger +import qualified Rahm.Desktop.StackSet as S import Rahm.Desktop.Theater (getTheaters) - +import Rahm.Desktop.Workspaces (WorkspaceState (..), getPopulatedWorkspaces) +import System.IO (Handle, hPutStrLn, hSetEncoding, utf8) +import Text.Printf +import XMonad (X) import qualified XMonad as X -import qualified Rahm.Desktop.StackSet as S +import XMonad.Util.NamedWindows (getName) +import XMonad.Util.Run (spawnPipe) data XMobarLog = XMobarLog Handle @@ -35,7 +34,6 @@ spawnXMobar = do hSetEncoding pipe utf8 return (XMobarLog pipe) - -- XMonad Log Hook meant to be used with the XMonad config logHook. xMobarLogHook :: XMobarLog -> X () xMobarLogHook (XMobarLog xmproc) = do @@ -48,60 +46,60 @@ xMobarLogHook (XMobarLog xmproc) = do title <- maybe (pure "") (fmap show . getName) . S.peek $ winset let wss = getPopulatedWorkspaces winset - let log = trunc 80 $ execWriter $ do - tell " " - tell (toChangeLayoutAction layoutXpm) - tell " " - tell $ logLevelToXMobar loglevel - - forM_ theaters $ \theater -> case theater of - (Just n, _, True) -> do - tell "" - tell n - tell " " - - (Just n, _, False) -> do - tell "" - tell n - tell " " - - _ -> return () - - if not (null theaters) - then tell "| " - else return () - - forM_ wss $ \(t, ws) -> do - case t of - Current -> tell "" - Visible -> tell "" - Hidden -> tell "" - - tell $ toAction $ S.tag ws - tell " " - - tell " " - tell title - tell "" + let log = trunc 80 $ + execWriter $ do + tell " " + tell (toChangeLayoutAction layoutXpm) + tell " " + tell $ logLevelToXMobar loglevel + + forM_ theaters $ \theater -> case theater of + (Just n, _, True) -> do + tell "" + tell n + tell " " + (Just n, _, False) -> do + tell "" + tell n + tell " " + _ -> return () + + if not (null theaters) + then tell "| " + else return () + + forM_ wss $ \(t, ws) -> do + case t of + Current -> tell "" + Visible -> tell "" + Hidden -> tell "" + + tell $ toAction $ S.tag ws + tell " " + + tell " " + tell title + tell "" logs Trace "XMobar: %s" log X.io $ hPutStrLn xmproc log - where - toAction [ch] | isAsciiUpper ch || - isAsciiLower ch || - isDigit ch = - printf "%s" [ch] [ch] [ch] + toAction [ch] + | isAsciiUpper ch + || isAsciiLower ch + || isDigit ch = + printf "%s" [ch] [ch] [ch] toAction ch = ch toChangeLayoutAction :: String -> String toChangeLayoutAction = - printf "\ + printf + "\ \%s" logLevelToXMobar Trace = "[Trace] " logLevelToXMobar Debug = "[Debug] " - logLevelToXMobar Warn = "[Warn] " + logLevelToXMobar Warn = "[Warn] " logLevelToXMobar Error = "[Error] " logLevelToXMobar Fatal = "[Fatal] " logLevelToXMobar _ = "" @@ -112,15 +110,14 @@ trunc :: Int -> String -> String trunc amt str = reverse $ trunc' False amt str [] where trunc' _ _ [] acc = acc - trunc' ignore amt (a:as) acc = + trunc' ignore amt (a : as) acc = case a of '<' -> trunc' True amt as (a : acc) '>' -> trunc' False amt as (a : acc) _ -> if ignore then trunc' True amt as (a : acc) - else - case amt of - 0 -> trunc' False 0 as acc - 3 -> trunc' False 0 as ("..." ++ acc) - _ -> trunc' False (amt - 1) as (a : acc) + else case amt of + 0 -> trunc' False 0 as acc + 3 -> trunc' False 0 as ("..." ++ acc) + _ -> trunc' False (amt - 1) as (a : acc) -- cgit