diff options
author | jao <jao@gnu.org> | 2022-02-04 02:12:32 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-02-04 02:12:32 +0000 |
commit | c1b6c382d8b020238e64c811bcc6f905f0f5390d (patch) | |
tree | e5d530a35ce67be21a87614c1f35f250ebea5ceb /src/Xmobar/Text/Pango.hs | |
parent | 34bb65029f0fdcb3f88043b3b0ca6ebd46bee161 (diff) | |
download | xmobar-c1b6c382d8b020238e64c811bcc6f905f0f5390d.tar.gz xmobar-c1b6c382d8b020238e64c811bcc6f905f0f5390d.tar.bz2 |
Refactoring: Xmobar.Text.{Ansi,Pango,Output}
Diffstat (limited to 'src/Xmobar/Text/Pango.hs')
-rw-r--r-- | src/Xmobar/Text/Pango.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Xmobar/Text/Pango.hs b/src/Xmobar/Text/Pango.hs new file mode 100644 index 0000000..b8205ef --- /dev/null +++ b/src/Xmobar/Text/Pango.hs @@ -0,0 +1,35 @@ +------------------------------------------------------------------------------ +-- | +-- Module: Xmobar.Text.Pango +-- Copyright: (c) 2022 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Author: Pavel Kalugin +-- Maintainer: jao@gnu.org +-- Stability: unstable +-- Portability: portable +-- Created: Fri Feb 4, 2022 01:15 +-- +-- +-- Codification with Pango markup +-- +------------------------------------------------------------------------------ + +module Xmobar.Text.Pango (withPangoColor) where + +import Text.Printf (printf) + +replaceAll :: (Eq a) => a -> [a] -> [a] -> [a] +replaceAll c s = concatMap (\x -> if x == c then s else [x]) + +xmlEscape :: String -> String +xmlEscape s = replaceAll '"' """ $ + replaceAll '\'' "'" $ + replaceAll '<' "<" $ + replaceAll '>' ">" $ + replaceAll '&' "&" s + +withPangoColor :: (String, String) -> String -> String +withPangoColor (fg, bg) s = + printf fmt (xmlEscape fg) (xmlEscape bg) (xmlEscape s) + where fmt = "<span foreground=\"%s\" background=\"%s\">%s</span>" |