From 4c2d70afa01c79c9de940c30046cd518b48436f8 Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Mon, 8 Jul 2013 16:48:13 +0200 Subject: Escape dzen markup and remove xmobar tags from window titles by default. Ignore-this: cf56bff752fbf78ea06d5c0cb755f615 The issue was that window titles, such as those set by, for example a browser, could set the window title to display something like " -- ??? add an xmobarEscape function? --- | Strip xmobar markup. +-- | Strip xmobar markup, specifically the , and tags and +-- the matching tags like . xmobarStrip :: String -> String -xmobarStrip = strip [] where +xmobarStrip = xmobarStripTags ["fc","icon","action"] where + +xmobarStripTags :: [String] -- ^ tags + -> String -> String -- ^ with all ... removed +xmobarStripTags tags = strip [] where + strip keep [] = keep strip keep x - | null x = keep - | "') $ x) - | "" `isPrefixOf` x = strip keep (drop 5 x) - | '<' == head x = strip (keep ++ "<") (tail x) - | otherwise = let (good,x') = span (/= '<') x - in strip (keep ++ good) x' + | rest: _ <- mapMaybe dropTag tags = strip keep rest + + + | '<':xs <- x = strip (keep ++ "<") xs + | (good,x') <- span (/= '<') x = strip (keep ++ good) x' -- this is n^2 bad... but titles have few tags + where dropTag :: String -> Maybe String + dropTag tag = msum [fmap dropTilClose (openTag tag `stripPrefix` x), + closeTag tag `stripPrefix` x] + + dropTilClose, openTag, closeTag :: String -> String + dropTilClose = drop 1 . dropWhile (/= '>') + openTag str = "<" ++ str ++ "=" + closeTag str = "" -- | The 'PP' type allows the user to customize the formatting of -- status information. @@ -427,6 +441,8 @@ data PP = PP { ppCurrent :: WorkspaceId -> String -- ^ separator to use between workspace tags , ppTitle :: String -> String -- ^ window title format + , ppTitleSanitize :: String -> String + -- ^ escape / sanitizes input to 'ppTitle' , ppLayout :: String -> String -- ^ layout name format , ppOrder :: [String] -> [String] @@ -472,6 +488,7 @@ instance Default PP where , ppSep = " : " , ppWsSep = " " , ppTitle = shorten 80 + , ppTitleSanitize = xmobarStrip . dzenEscape , ppLayout = id , ppOrder = id , ppOutput = putStrLn -- cgit v1.2.3