diff options
author | Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com> | 2025-06-01 11:04:25 +0100 |
---|---|---|
committer | Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com> | 2025-06-01 11:04:25 +0100 |
commit | 49a9bfe9a138dd43ab213255a0130b222ba2acc3 (patch) | |
tree | 04005931f934d50826b02aa30df05e8b2e243f6c /src/Xmobar/Plugins | |
parent | 5403b83d03d4771b09b9e9b04f1d9ec8db3df804 (diff) | |
download | xmobar-49a9bfe9a138dd43ab213255a0130b222ba2acc3.tar.gz xmobar-49a9bfe9a138dd43ab213255a0130b222ba2acc3.tar.bz2 |
Accordion: some renaming and reformatting
Diffstat (limited to 'src/Xmobar/Plugins')
-rw-r--r-- | src/Xmobar/Plugins/Accordion.hs | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/Xmobar/Plugins/Accordion.hs b/src/Xmobar/Plugins/Accordion.hs index 6377928..6922fba 100644 --- a/src/Xmobar/Plugins/Accordion.hs +++ b/src/Xmobar/Plugins/Accordion.hs @@ -23,7 +23,7 @@ import Control.Monad (forever, join, when) import Control.Monad.IO.Class (liftIO) import Control.Monad.Reader (runReaderT, ask) import Control.Monad.State.Strict (evalStateT, get, modify') -import Data.IORef (atomicModifyIORef', newIORef, readIORef) +import Data.IORef (atomicModifyIORef', newIORef, readIORef, IORef) import Data.Maybe (isJust) import System.Directory (removeFile) import System.Exit (ExitCode(..)) @@ -61,8 +61,8 @@ defaultTuning = Tuning { instance (Exec a, Read a, Show a) => Exec (Accordion a) where alias (Accordion Tuning { alias' = name } _) = name start (Accordion Tuning { initial = initial' - , expand = expand' - , shrink = shrink' } + , expand = expandIcon + , shrink = shrinkIcon } runnables) cb = do clicked <- newIORef Nothing @@ -74,24 +74,35 @@ instance (Exec a, Read a, Show a) => Exec (Accordion a) where ExitSuccess -> atomicModifyIORef' clicked (const (Just (), ())) ExitFailure _ -> error "how is this possible?") (const $ do - srefs <- mapM (newIORef . const "") runnables - foldr (\(runnable, sref) acc -> withAsync (start runnable (writeToRef sref)) (const acc)) + strRefs <- mapM (newIORef . const "") runnables + foldr (\(runnable, strRef) acc -> withAsync (start runnable (writeToRef strRef)) (const acc)) (forever (do liftIO (tenthSeconds 1) clicked' <- liftIO $ readIORef clicked when (isJust clicked') (do liftIO $ clear clicked modify' not) b <- get - if b then loop pipe else liftIO $ cb (click pipe expand')) - `runReaderT` srefs `evalStateT` initial') - (zip runnables srefs)) + if b + then loop pipe + else liftIO $ cb (attachClick pipe expandIcon)) + `runReaderT` strRefs + `evalStateT` initial') + (zip runnables strRefs)) `finally` removeFile pipe where - click file icon = "<action=`echo 1 > " ++ file ++ "`>" ++ icon ++ "</action>" - clear = (`atomicModifyIORef'` const (Nothing, ())) - removeLinebreak = init - writeToRef strRef = atomicModifyIORef' strRef . const . (,()) loop p = do - srefs <- ask - text <- join <$> mapM (liftIO . readIORef) srefs - liftIO $ cb $ text ++ click p shrink' + strRefs <- ask + text <- join <$> mapM (liftIO . readIORef) strRefs + liftIO $ cb $ text ++ attachClick p shrinkIcon + +writeToRef :: IORef a -> a -> IO () +writeToRef strRef = atomicModifyIORef' strRef . const . (,()) + +clear :: IORef (Maybe a) -> IO () +clear = (`atomicModifyIORef'` const (Nothing, ())) + +removeLinebreak :: [a] -> [a] +removeLinebreak = init + +attachClick :: String -> String -> String +attachClick file icon = "<action=`echo 1 > " ++ file ++ "`>" ++ icon ++ "</action>" |