diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Xmobar/Text/Output.hs | 24 | ||||
-rw-r--r-- | src/Xmobar/Text/Pango.hs | 8 |
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>" |