Merge pull request #802 from geekosaur/801-dynamicLogString

`dynamicLogString` forces its result and recovers
This commit is contained in:
Tomáš Janoušek 2023-02-20 21:45:42 +00:00 committed by GitHub
commit 5324f53501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -114,6 +114,12 @@
and `ClassnamesFormat`. These are all equivalents of their `Title` and `ClassnamesFormat`. These are all equivalents of their `Title`
counterparts, allowing logging the window classname instead. counterparts, allowing logging the window classname instead.
* `XMonad.Hooks.StatusBar.PP`
- `dynamicLogString` now forces its result and produces an error string if
it throws an exception. Use `dynamicLogString'` if for some reason you
need the old behavior.
* `XMonad.Util.EZConfig` * `XMonad.Util.EZConfig`
- Added `remapKeysP`, which remaps keybindings from one binding to - Added `remapKeysP`, which remaps keybindings from one binding to

View File

@ -32,6 +32,7 @@ module XMonad.Hooks.StatusBar.PP (
-- * Build your own formatter -- * Build your own formatter
PP(..), def, PP(..), def,
dynamicLogString, dynamicLogString,
dynamicLogString',
dynamicLogWithPP, dynamicLogWithPP,
-- * Predicates and formatters -- * Predicates and formatters
@ -55,6 +56,7 @@ module XMonad.Hooks.StatusBar.PP (
) where ) where
import Control.Monad.Reader import Control.Monad.Reader
import Control.DeepSeq
import XMonad import XMonad
import XMonad.Prelude import XMonad.Prelude
@ -181,7 +183,14 @@ dynamicLogWithPP pp = dynamicLogString pp >>= io . ppOutput pp
-- allow for further processing, or use in some application other than -- allow for further processing, or use in some application other than
-- a status bar. -- a status bar.
dynamicLogString :: PP -> X String dynamicLogString :: PP -> X String
dynamicLogString pp = do dynamicLogString pp = userCodeDef "_|_" (dynamicLogString' pp)
-- | The guts of 'dynamicLogString'. Forces the result, so it may throw
-- an exception (most commonly because 'ppOrder' is non-total). Use
-- 'dynamicLogString' for a version that catches the exception and
-- produces an error string.
dynamicLogString' :: PP -> X String
dynamicLogString' pp = do
winset <- gets windowset winset <- gets windowset
urgents <- readUrgents urgents <- readUrgents
@ -199,7 +208,7 @@ dynamicLogString pp = do
-- window title -- window title
wt <- maybe (pure "") (fmap show . getName) . S.peek $ winset wt <- maybe (pure "") (fmap show . getName) . S.peek $ winset
return $ sepBy (ppSep pp) . ppOrder pp $ return $! force $ sepBy (ppSep pp) . ppOrder pp $
[ ws [ ws
, ppLayout pp ld , ppLayout pp ld
, ppTitle pp $ ppTitleSanitize pp wt , ppTitle pp $ ppTitleSanitize pp wt