summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Text/Output.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-02-04 02:12:32 +0000
committerjao <jao@gnu.org>2022-02-04 02:12:32 +0000
commitc1b6c382d8b020238e64c811bcc6f905f0f5390d (patch)
treee5d530a35ce67be21a87614c1f35f250ebea5ceb /src/Xmobar/Text/Output.hs
parent34bb65029f0fdcb3f88043b3b0ca6ebd46bee161 (diff)
downloadxmobar-c1b6c382d8b020238e64c811bcc6f905f0f5390d.tar.gz
xmobar-c1b6c382d8b020238e64c811bcc6f905f0f5390d.tar.bz2
Refactoring: Xmobar.Text.{Ansi,Pango,Output}
Diffstat (limited to 'src/Xmobar/Text/Output.hs')
-rw-r--r--src/Xmobar/Text/Output.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Xmobar/Text/Output.hs b/src/Xmobar/Text/Output.hs
new file mode 100644
index 0000000..3754bd3
--- /dev/null
+++ b/src/Xmobar/Text/Output.hs
@@ -0,0 +1,41 @@
+-- |
+-- Module: Xmobar.Text.Output
+-- Copyright: (c) 2022 Jose Antonio Ortega Ruiz
+-- License: BSD3-style (see LICENSE)
+--
+-- Maintainer: jao@gnu.org
+-- Stability: unstable
+-- Portability: portable
+-- Created: Fri Feb 4, 2022 01:10
+--
+--
+-- Format segments emitted by Commands into output strings
+--
+------------------------------------------------------------------------------
+
+module Xmobar.Text.Output (formatSegment) where
+
+import Xmobar.Config.Types (Config(textOutputFormat), TextOutputFormat(..))
+import Xmobar.Run.Parsers ( Segment
+ , Widget(..)
+ , tColorsString
+ , colorComponents)
+
+import Xmobar.Text.Ansi (withAnsiColor)
+import Xmobar.Text.Pango (withPangoColor)
+
+withColor :: TextOutputFormat -> (String, String) -> String -> String
+withColor format color = case format of
+ Plain -> id
+ Ansi -> withAnsiColor color
+ Pango -> withPangoColor color
+
+
+formatSegment :: Config -> Segment -> String
+formatSegment 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 _ _ = ""