force capitalization of player/goalie names in player selection
This commit is contained in:
parent
4ca0b54de2
commit
996bad94f1
|
@ -157,7 +157,7 @@ selectPrompt params = Prompt
|
||||||
in "F" ++ show n ++ ") " ++ desc)
|
in "F" ++ show n ++ ") " ++ desc)
|
||||||
results
|
results
|
||||||
C.moveCursor row col
|
C.moveCursor row col
|
||||||
, promptProcessChar = \ch -> (++[ch])
|
, promptProcessChar = spProcessChar params
|
||||||
, promptAction = \sStr -> if null sStr
|
, promptAction = \sStr -> if null sStr
|
||||||
then spCallback params Nothing
|
then spCallback params Nothing
|
||||||
else do
|
else do
|
||||||
|
@ -218,6 +218,7 @@ selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
||||||
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
||||||
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
|
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
|
||||||
, spElemDesc = playerSummary
|
, spElemDesc = playerSummary
|
||||||
|
, spProcessChar = capitalizeName
|
||||||
, spCallback = callback
|
, spCallback = callback
|
||||||
, spNotFound = \sStr -> do
|
, spNotFound = \sStr -> do
|
||||||
mode <- gets (^.progMode)
|
mode <- gets (^.progMode)
|
||||||
|
@ -246,6 +247,7 @@ selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
||||||
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
||||||
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
|
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
|
||||||
, spElemDesc = goalieSummary
|
, spElemDesc = goalieSummary
|
||||||
|
, spProcessChar = capitalizeName
|
||||||
, spCallback = callback
|
, spCallback = callback
|
||||||
, spNotFound = \sStr -> do
|
, spNotFound = \sStr -> do
|
||||||
mode <- gets (^.progMode)
|
mode <- gets (^.progMode)
|
||||||
|
|
|
@ -622,6 +622,8 @@ data SelectParams a = SelectParams
|
||||||
-- ^ Search function looking for an exact match
|
-- ^ Search function looking for an exact match
|
||||||
, spElemDesc :: a -> String
|
, spElemDesc :: a -> String
|
||||||
-- ^ Provides a string description of an element
|
-- ^ Provides a string description of an element
|
||||||
|
, spProcessChar :: Char -> String -> String
|
||||||
|
-- ^ Processes a character entered by the user
|
||||||
, spCallback :: Maybe Int -> Action ()
|
, spCallback :: Maybe Int -> Action ()
|
||||||
-- ^ The function when the selection is made
|
-- ^ The function when the selection is made
|
||||||
, spNotFound :: String -> Action ()
|
, spNotFound :: String -> Action ()
|
||||||
|
|
|
@ -19,8 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Mtlstats.Util (nth, modifyNth, updateMap, slice) where
|
module Mtlstats.Util
|
||||||
|
( nth
|
||||||
|
, modifyNth
|
||||||
|
, updateMap
|
||||||
|
, slice
|
||||||
|
, capitalizeName
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Char (isSpace, toUpper)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
-- | Attempt to select the element from a list at a given index
|
-- | Attempt to select the element from a list at a given index
|
||||||
|
@ -75,3 +82,25 @@ slice
|
||||||
-- ^ The list to take a subset of
|
-- ^ The list to take a subset of
|
||||||
-> [a]
|
-> [a]
|
||||||
slice offset len = take len . drop offset
|
slice offset len = take len . drop offset
|
||||||
|
|
||||||
|
-- | Name capitalization function for a player
|
||||||
|
capitalizeName
|
||||||
|
:: Char
|
||||||
|
-- ^ The character being input
|
||||||
|
-> String
|
||||||
|
-- ^ The current string
|
||||||
|
-> String
|
||||||
|
-- ^ The resulting string
|
||||||
|
capitalizeName ch str = str ++ [ch']
|
||||||
|
where
|
||||||
|
ch' = if lockFlag str
|
||||||
|
then toUpper ch
|
||||||
|
else ch
|
||||||
|
lockFlag "" = True
|
||||||
|
lockFlag (c:cs)
|
||||||
|
| c == ',' = lockFlag' cs
|
||||||
|
| otherwise = lockFlag cs
|
||||||
|
lockFlag' "" = True
|
||||||
|
lockFlag' (c:cs)
|
||||||
|
| isSpace c = lockFlag' cs
|
||||||
|
| otherwise = False
|
||||||
|
|
|
@ -32,6 +32,7 @@ spec = describe "Mtlstats.Util" $ do
|
||||||
modifyNthSpec
|
modifyNthSpec
|
||||||
updateMapSpec
|
updateMapSpec
|
||||||
sliceSpec
|
sliceSpec
|
||||||
|
capitalizeNameSpec
|
||||||
|
|
||||||
nthSpec :: Spec
|
nthSpec :: Spec
|
||||||
nthSpec = describe "nth" $ mapM_
|
nthSpec = describe "nth" $ mapM_
|
||||||
|
@ -93,3 +94,23 @@ sliceSpec = describe "slice" $ do
|
||||||
context "negative offset" $
|
context "negative offset" $
|
||||||
it "should return the correct number of elements from the beginning" $
|
it "should return the correct number of elements from the beginning" $
|
||||||
slice (-10) 2 list `shouldBe` [2, 4]
|
slice (-10) 2 list `shouldBe` [2, 4]
|
||||||
|
|
||||||
|
capitalizeNameSpec :: Spec
|
||||||
|
capitalizeNameSpec = describe "capitalizeName" $ mapM_
|
||||||
|
(\(label, ch, str, expected) -> context label $
|
||||||
|
it ("should be " ++ expected) $
|
||||||
|
capitalizeName ch str `shouldBe` expected)
|
||||||
|
-- label, character, string, expected
|
||||||
|
[ ( "initial lower", 'a', "", "A" )
|
||||||
|
, ( "initial upper", 'A', "", "A" )
|
||||||
|
, ( "initial non-alpha", '0', "", "0" )
|
||||||
|
, ( "pre-comma lower", 'a', "A", "AA" )
|
||||||
|
, ( "pre-comma upper", 'A', "A", "AA" )
|
||||||
|
, ( "pre-comma non-alpha", '0', "A", "A0" )
|
||||||
|
, ( "post-comma first lower", 'a', "FOO, ", "FOO, A" )
|
||||||
|
, ( "post-comma first upper", 'A', "FOO, ", "FOO, A" )
|
||||||
|
, ( "post-comma first non-alpha", '0', "FOO, ", "FOO, 0" )
|
||||||
|
, ( "unrestricted upper", 'A', "FOO, A", "FOO, AA" )
|
||||||
|
, ( "unrestricted lower", 'a', "FOO, A", "FOO, Aa" )
|
||||||
|
, ( "unrestricted non-alpha", '0', "FOO, A", "FOO, A0" )
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user