Merge pull request #511 from xsebek/keybinding-name-from-just

Replace keybinding name fromJust with maybe

This change fixes a problem where a key event with no name in a KeyEvents would cause a fromJust exception in the pretty-printer. This change ensure that the pretty-printer falls back to a placeholder representation for the key event.
This commit is contained in:
Jonathan Daugherty 2024-06-29 22:44:37 -07:00 committed by GitHub
commit d09f31e789
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,7 +25,6 @@ where
import Brick
import Data.List (sort, intersperse)
import Data.Maybe (fromJust)
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid ((<>))
#endif
@ -124,19 +123,19 @@ mkKeybindEventHelp kc h =
ByKey b ->
(Comment "(non-customizable key)", [Verbatim $ ppBinding b])
ByEvent ev ->
let name = fromJust $ keyEventName (keyConfigEvents kc) ev
let name = maybe (Comment "(unnamed)") Verbatim $ keyEventName (keyConfigEvents kc) ev
in case lookupKeyConfigBindings kc ev of
Nothing ->
if not (null (allDefaultBindings kc ev))
then (Verbatim name, Verbatim <$> ppBinding <$> allDefaultBindings kc ev)
else (Verbatim name, unbound)
then (name, Verbatim <$> ppBinding <$> allDefaultBindings kc ev)
else (name, unbound)
Just Unbound ->
(Verbatim name, unbound)
(name, unbound)
Just (BindingList bs) ->
let result = if not (null bs)
then Verbatim <$> ppBinding <$> bs
else unbound
in (Verbatim name, result)
in (name, result)
in (label, handlerDescription $ kehHandler h, evText)
-- | Build a 'Widget' displaying key binding information for a single