summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-02-08 00:21:31 +0000
committerjao <jao@gnu.org>2022-02-08 00:21:31 +0000
commit48dc39edaca5ff4e011ea9475fe8b75d24b5e4c4 (patch)
tree47f849a34d3e5eb92b5333984a0beffccf0b4ff1 /src
parentc75f31c0887b12c1e9fd63a05a494d703c43576a (diff)
downloadxmobar-48dc39edaca5ff4e011ea9475fe8b75d24b5e4c4.tar.gz
xmobar-48dc39edaca5ff4e011ea9475fe8b75d24b5e4c4.tar.bz2
pango output: fonts
Diffstat (limited to 'src')
-rw-r--r--src/Xmobar/Text/Output.hs24
-rw-r--r--src/Xmobar/Text/Pango.hs8
2 files changed, 20 insertions, 12 deletions
diff --git a/src/Xmobar/Text/Output.hs b/src/Xmobar/Text/Output.hs
index 134dfed..783a5bb 100644
--- a/src/Xmobar/Text/Output.hs
+++ b/src/Xmobar/Text/Output.hs
@@ -15,7 +15,8 @@
module Xmobar.Text.Output (initLoop, format) where
-import Xmobar.Config.Types (Config(textOutputFormat), TextOutputFormat(..))
+import Xmobar.Config.Types (Config(textOutputFormat, additionalFonts, font)
+ , TextOutputFormat(..))
import Xmobar.Run.Parsers ( Segment
, Widget(..)
, parseString
@@ -23,7 +24,7 @@ import Xmobar.Run.Parsers ( Segment
, colorComponents)
import Xmobar.Text.Ansi (withAnsiColor)
-import Xmobar.Text.Pango (withPangoColor)
+import Xmobar.Text.Pango (withPangoMarkup)
import Xmobar.Text.Swaybar (formatSwaybar, prepare)
initLoop :: Config -> IO ()
@@ -31,16 +32,17 @@ initLoop conf = case textOutputFormat conf of
Swaybar -> prepare
_ -> return ()
-withColor :: TextOutputFormat -> (String, String) -> String -> String
-withColor Ansi c = withAnsiColor c
-withColor Pango c = withPangoColor c
-withColor _ _ = id
-
formatWithColor :: Config -> Segment -> String
-formatWithColor conf (Text s, info, _, _) =
- withColor (textOutputFormat conf) components s
- where components = colorComponents conf color
- color = tColorsString info
+formatWithColor conf (Text s, info, idx, _) =
+ case textOutputFormat conf of
+ Ansi -> withAnsiColor (fg, bg) s
+ Pango -> withPangoMarkup fg bg fn s
+ _ -> s
+ where (fg, bg) = colorComponents conf (tColorsString info)
+ fonts = additionalFonts conf
+ fn = if idx < 1 || idx > length fonts
+ then font conf
+ else fonts !! (idx - 1)
formatWithColor conf (Hspace n, i, x, y) =
formatWithColor conf (Text $ replicate (fromIntegral n) ' ', i, x, y)
formatWithColor _ _ = ""
diff --git a/src/Xmobar/Text/Pango.hs b/src/Xmobar/Text/Pango.hs
index 38d1b5b..30ec76f 100644
--- a/src/Xmobar/Text/Pango.hs
+++ b/src/Xmobar/Text/Pango.hs
@@ -15,7 +15,7 @@
--
------------------------------------------------------------------------------
-module Xmobar.Text.Pango (withPangoColor, withPangoFont) where
+module Xmobar.Text.Pango (withPangoColor, withPangoFont, withPangoMarkup) where
import Text.Printf (printf)
import Data.List (isPrefixOf)
@@ -39,3 +39,9 @@ withPangoFont :: String -> String -> String
withPangoFont font txt = printf fmt pfn (xmlEscape txt)
where fmt = "<span font=\"%s\">%s</span>"
pfn = if "xft:" `isPrefixOf` font then drop 4 font else font
+
+withPangoMarkup :: String -> String -> String -> String -> String
+withPangoMarkup fg bg font txt =
+ printf fmt pfn (xmlEscape fg) (xmlEscape bg) (xmlEscape txt)
+ where pfn = if isPrefixOf "xft:" font then drop 4 font else font
+ fmt = "<span font=\"%s\" foreground=\"%s\" background=\"%s\">%s</span>"