X.H.DynamicLog: Add shorten' and shortenLeft' (customizable end)

This commit is contained in:
Tomas Janousek
2020-12-13 21:29:12 +00:00
parent 27f03ad9c5
commit 89646d75fd
2 changed files with 18 additions and 11 deletions

View File

@@ -176,6 +176,9 @@
- Added `shortenLeft` function, like existing `shorten` but shortens by - Added `shortenLeft` function, like existing `shorten` but shortens by
truncating from left instead of right. Useful for showing directories. 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 - Added `filterOutWsPP` for filtering out certain workspaces from being
displayed. displayed.
@@ -309,7 +312,7 @@
* `XMonad.Util.DebugWindow` * `XMonad.Util.DebugWindow`
Fixed a bottom in `debugWindow` when used on windows with UTF8 encoded titles. Fixed a bottom in `debugWindow` when used on windows with UTF8 encoded titles.
* `XMonad.Config.Xfce` * `XMonad.Config.Xfce`
Set `terminal` to `xfce4-terminal`. Set `terminal` to `xfce4-terminal`.

View File

@@ -43,7 +43,7 @@ module XMonad.Hooks.DynamicLog (
dzenPP, xmobarPP, sjanssenPP, byorgeyPP, dzenPP, xmobarPP, sjanssenPP, byorgeyPP,
-- * Formatting utilities -- * Formatting utilities
wrap, pad, trim, shorten, shortenLeft, wrap, pad, trim, shorten, shorten', shortenLeft, shortenLeft',
xmobarColor, xmobarAction, xmobarBorder, xmobarColor, xmobarAction, xmobarBorder,
xmobarRaw, xmobarStrip, xmobarStripTags, xmobarRaw, xmobarStrip, xmobarStripTags,
dzenColor, dzenEscape, dzenStrip, filterOutWsPP, dzenColor, dzenEscape, dzenStrip, filterOutWsPP,
@@ -386,18 +386,22 @@ trim = f . f
-- | Limit a string to a certain length, adding "..." if truncated. -- | Limit a string to a certain length, adding "..." if truncated.
shorten :: Int -> String -> String shorten :: Int -> String -> String
shorten n xs | length xs < n = xs shorten = shorten' "..."
| otherwise = take (n - length end) xs ++ end
where -- | Limit a string to a certain length, adding @end@ if truncated.
end = "..." 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. -- | Like 'shorten', but truncate from the left instead of right.
shortenLeft :: Int -> String -> String shortenLeft :: Int -> String -> String
shortenLeft n xs | l < n = xs shortenLeft = shortenLeft' "..."
| otherwise = end ++ (drop (l - n + length end) xs)
where -- | Like 'shorten'', but truncate from the left instead of right.
end = "..." shortenLeft' :: String -> Int -> String -> String
l = length xs 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 -- | Output a list of strings, ignoring empty ones and separating the
-- rest with the given separator. -- rest with the given separator.