diff --git a/CHANGES.md b/CHANGES.md index dd41be1e..22f6e2e3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -176,6 +176,9 @@ - Added `shortenLeft` function, like existing `shorten` but shortens by truncating from left instead of right. Useful for showing directories. + - Added `shorten'` and `shortenLeft'` functions with customizable overflow + markers. + - Added `filterOutWsPP` for filtering out certain workspaces from being displayed. @@ -309,7 +312,7 @@ * `XMonad.Util.DebugWindow` Fixed a bottom in `debugWindow` when used on windows with UTF8 encoded titles. - + * `XMonad.Config.Xfce` Set `terminal` to `xfce4-terminal`. diff --git a/XMonad/Hooks/DynamicLog.hs b/XMonad/Hooks/DynamicLog.hs index 40c7ebbf..5ccc3061 100644 --- a/XMonad/Hooks/DynamicLog.hs +++ b/XMonad/Hooks/DynamicLog.hs @@ -43,7 +43,7 @@ module XMonad.Hooks.DynamicLog ( dzenPP, xmobarPP, sjanssenPP, byorgeyPP, -- * Formatting utilities - wrap, pad, trim, shorten, shortenLeft, + wrap, pad, trim, shorten, shorten', shortenLeft, shortenLeft', xmobarColor, xmobarAction, xmobarBorder, xmobarRaw, xmobarStrip, xmobarStripTags, dzenColor, dzenEscape, dzenStrip, filterOutWsPP, @@ -386,18 +386,22 @@ trim = f . f -- | Limit a string to a certain length, adding "..." if truncated. shorten :: Int -> String -> String -shorten n xs | length xs < n = xs - | otherwise = take (n - length end) xs ++ end - where - end = "..." +shorten = shorten' "..." + +-- | Limit a string to a certain length, adding @end@ if truncated. +shorten' :: String -> Int -> String -> String +shorten' end n xs | length xs < n = xs + | otherwise = take (n - length end) xs ++ 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 +shortenLeft = shortenLeft' "..." + +-- | Like 'shorten'', but truncate from the left instead of right. +shortenLeft' :: String -> Int -> String -> String +shortenLeft' end n xs | l < n = xs + | otherwise = end ++ (drop (l - n + length end) xs) + where l = length xs -- | Output a list of strings, ignoring empty ones and separating the -- rest with the given separator.