'XMonad.Hooks.DynamicLog': xmobar tags

Support xmobar's <action> and <raw> tags.
This commit is contained in:
Yclept Nemo 2018-04-19 18:30:30 -04:00
parent 5f2afb08e9
commit 348861da00

View File

@ -43,8 +43,8 @@ module XMonad.Hooks.DynamicLog (
-- * Formatting utilities -- * Formatting utilities
wrap, pad, trim, shorten, wrap, pad, trim, shorten,
xmobarColor, xmobarStrip, xmobarColor, xmobarAction, xmobarRaw,
xmobarStripTags, xmobarStrip, xmobarStripTags,
dzenColor, dzenEscape, dzenStrip, dzenColor, dzenEscape, dzenStrip,
-- * Internal formatting functions -- * Internal formatting functions
@ -417,6 +417,31 @@ xmobarColor :: String -- ^ foreground color: a color name, or #rrggbb format
xmobarColor fg bg = wrap t "</fc>" xmobarColor fg bg = wrap t "</fc>"
where t = concat ["<fc=", fg, if null bg then "" else "," ++ bg, ">"] where t = concat ["<fc=", fg, if null bg then "" else "," ++ bg, ">"]
-- | Encapsulate text with an action. The text will be displayed, and the
-- action executed when the displayed text is clicked. Illegal input is not
-- filtered, allowing xmobar to display any parse errors. Uses xmobar's new
-- syntax wherein the command is surrounded by backticks.
xmobarAction :: String
-- ^ Command. Use of backticks (`) will cause a parse error.
-> String
-- ^ Buttons 1-5, such as "145". Other characters will cause a
-- parse error.
-> String
-- ^ Displayed/wrapped text.
-> String
xmobarAction command button = wrap l r
where
l = "<action=`" ++ command ++ "` button=" ++ button ++ ">"
r = "</action>"
-- | Encapsulate arbitrary text for display only, i.e. untrusted content if
-- wrapped (perhaps from window titles) will be displayed only, with all tags
-- ignored. Introduced in xmobar 0.21; see their documentation. Be careful not
-- to shorten the result.
xmobarRaw :: String -> String
xmobarRaw "" = ""
xmobarRaw s = concat ["<raw=", show $ length s, ":", s, "/>"]
-- ??? add an xmobarEscape function? -- ??? add an xmobarEscape function?
-- | Strip xmobar markup, specifically the <fc>, <icon> and <action> tags and -- | Strip xmobar markup, specifically the <fc>, <icon> and <action> tags and