X.H.DynamicLog: Add shortenLeft

This can be sometimes useful, e.g. when showing a directory.
This commit is contained in:
Tomas Janousek 2020-11-04 14:53:23 +00:00
parent d5b64c1e5d
commit 0996e71c7e

View File

@ -43,7 +43,7 @@ module XMonad.Hooks.DynamicLog (
dzenPP, xmobarPP, sjanssenPP, byorgeyPP,
-- * Formatting utilities
wrap, pad, trim, shorten,
wrap, pad, trim, shorten, shortenLeft,
xmobarColor, xmobarAction, xmobarBorder,
xmobarRaw, xmobarStrip, xmobarStripTags,
dzenColor, dzenEscape, dzenStrip,
@ -391,6 +391,14 @@ shorten n xs | length xs < n = xs
where
end = "..."
-- | Like 'shorten', but truncate from the left instead of right.
shortenLeft :: Int -> String -> String
shortenLeft n xs | l < n = xs
| otherwise = end ++ (drop (l - n + length end) xs)
where
end = "..."
l = length xs
-- | Output a list of strings, ignoring empty ones and separating the
-- rest with the given separator.
sepBy :: String -- ^ separator