From 7437a181888f3e8938a943ae22962f21b1c03b1e Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 20 Jun 2021 16:44:12 -0400 Subject: fix(xanthous): Only use alphabetic chars for menu items Previously, we were using `smallestNotIn` for selecting new characters for menu items with duplicate chatacters - this uses the 'Bounded' instance for the type, which for Char meant the first character we would always select was \NUL - making it look like the menu item had no character, and making it impossible to actually select the menu item. This introduces an AlphaChar newtype, which is a wrapper around Char whose Bounded and Enum instances only use alphabetic characters (a-ZA-Z) and uses that for menu characters instead. Change-Id: If34ed9e9ce84f2bcb1cb87432cc6273f40b69f72 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3229 Reviewed-by: grfn Tested-by: BuildkiteCI --- users/grfn/xanthous/src/Xanthous/Game/Prompt.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'users/grfn/xanthous/src/Xanthous/Game') diff --git a/users/grfn/xanthous/src/Xanthous/Game/Prompt.hs b/users/grfn/xanthous/src/Xanthous/Game/Prompt.hs index 30b5fe7545e0..fa4c3903deb1 100644 --- a/users/grfn/xanthous/src/Xanthous/Game/Prompt.hs +++ b/users/grfn/xanthous/src/Xanthous/Game/Prompt.hs @@ -28,7 +28,8 @@ import Brick.Widgets.Edit (Editor, editorText, getEditContents) import Test.QuickCheck import Test.QuickCheck.Arbitrary.Generic -------------------------------------------------------------------------------- -import Xanthous.Util (smallestNotIn) +-------------------------------------------------------------------------------- +import Xanthous.Util (smallestNotIn, AlphaChar (..)) import Xanthous.Data (Direction, Position) import Xanthous.Data.App (ResourceName) import qualified Xanthous.Data.App as Resource @@ -175,7 +176,7 @@ mkMenuItems :: (MonoFoldable f, Element f ~ (Char, MenuOption a)) -> Map Char (MenuOption a) mkMenuItems = flip foldl' mempty $ \items (chr, option) -> let chr' = if has (ix chr) items - then smallestNotIn $ keys items + then getAlphaChar . smallestNotIn . map AlphaChar $ keys items else chr in items & at chr' ?~ option -- cgit 1.4.1