summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Text/Output.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xmobar/Text/Output.hs')
-rw-r--r--src/Xmobar/Text/Output.hs36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/Xmobar/Text/Output.hs b/src/Xmobar/Text/Output.hs
index 3754bd3..6aa1d56 100644
--- a/src/Xmobar/Text/Output.hs
+++ b/src/Xmobar/Text/Output.hs
@@ -9,33 +9,45 @@
-- Created: Fri Feb 4, 2022 01:10
--
--
--- Format segments emitted by Commands into output strings
+-- Format strings emitted by Commands into output strings
--
------------------------------------------------------------------------------
-module Xmobar.Text.Output (formatSegment) where
+module Xmobar.Text.Output (initLoop, format) where
import Xmobar.Config.Types (Config(textOutputFormat), TextOutputFormat(..))
import Xmobar.Run.Parsers ( Segment
, Widget(..)
+ , parseString
, tColorsString
, colorComponents)
import Xmobar.Text.Ansi (withAnsiColor)
import Xmobar.Text.Pango (withPangoColor)
+import Xmobar.Text.Swaybar (formatSwaybar, preamble)
-withColor :: TextOutputFormat -> (String, String) -> String -> String
-withColor format color = case format of
- Plain -> id
- Ansi -> withAnsiColor color
- Pango -> withPangoColor color
+initLoop :: Config -> IO ()
+initLoop conf = case textOutputFormat conf of
+ Swaybar -> putStrLn preamble
+ _ -> return ()
+withColor :: TextOutputFormat -> (String, String) -> String -> String
+withColor Ansi c = withAnsiColor c
+withColor Pango c = withPangoColor c
+withColor _ _ = id
-formatSegment :: Config -> Segment -> String
-formatSegment conf (Text s, info, _, _) =
+formatWithColor :: Config -> Segment -> String
+formatWithColor conf (Text s, info, _, _) =
withColor (textOutputFormat conf) components s
where components = colorComponents conf color
color = tColorsString info
-formatSegment conf (Hspace n, i, x, y) =
- formatSegment conf (Text $ replicate (fromIntegral n) ' ', i, x, y)
-formatSegment _ _ = ""
+formatWithColor conf (Hspace n, i, x, y) =
+ formatWithColor conf (Text $ replicate (fromIntegral n) ' ', i, x, y)
+formatWithColor _ _ = ""
+
+format :: Config -> String -> IO String
+format conf s = do
+ segments <- parseString conf s
+ case textOutputFormat conf of
+ Swaybar -> return $ formatSwaybar conf segments
+ _ -> return (concatMap (formatWithColor conf) segments)