allow lower case
- allow strPrompt to accept lower case letters - implemented ucStrPrompt which forces characters to upper case
This commit is contained in:
parent
cc495fa589
commit
f7cfd5d835
|
@ -28,6 +28,7 @@ module Mtlstats.Prompt (
|
||||||
promptControllerWith,
|
promptControllerWith,
|
||||||
promptController,
|
promptController,
|
||||||
strPrompt,
|
strPrompt,
|
||||||
|
ucStrPrompt,
|
||||||
numPrompt,
|
numPrompt,
|
||||||
selectPrompt,
|
selectPrompt,
|
||||||
-- * Individual prompts
|
-- * Individual prompts
|
||||||
|
@ -46,7 +47,7 @@ import Control.Monad.Extra (whenJust)
|
||||||
import Control.Monad.Trans.State (gets, modify)
|
import Control.Monad.Trans.State (gets, modify)
|
||||||
import Data.Char (isDigit, toUpper)
|
import Data.Char (isDigit, toUpper)
|
||||||
import Data.Foldable (forM_)
|
import Data.Foldable (forM_)
|
||||||
import Lens.Micro ((^.), (&), (.~), (?~))
|
import Lens.Micro ((^.), (&), (.~), (?~), (%~))
|
||||||
import Lens.Micro.Extras (view)
|
import Lens.Micro.Extras (view)
|
||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
@ -68,10 +69,8 @@ promptHandler p (C.EventCharacter '\n') = do
|
||||||
val <- gets $ view inputBuffer
|
val <- gets $ view inputBuffer
|
||||||
modify $ inputBuffer .~ ""
|
modify $ inputBuffer .~ ""
|
||||||
promptAction p val
|
promptAction p val
|
||||||
promptHandler p (C.EventCharacter c) = let
|
promptHandler p (C.EventCharacter c) =
|
||||||
c' = toUpper c
|
modify $ inputBuffer %~ promptProcessChar p c
|
||||||
in when (promptCharCheck p c') $
|
|
||||||
modify $ addChar c'
|
|
||||||
promptHandler _ (C.EventSpecialKey C.KeyBackspace) =
|
promptHandler _ (C.EventSpecialKey C.KeyBackspace) =
|
||||||
modify removeChar
|
modify removeChar
|
||||||
promptHandler p (C.EventSpecialKey k) =
|
promptHandler p (C.EventSpecialKey k) =
|
||||||
|
@ -112,11 +111,21 @@ strPrompt
|
||||||
-> Prompt
|
-> Prompt
|
||||||
strPrompt pStr act = Prompt
|
strPrompt pStr act = Prompt
|
||||||
{ promptDrawer = drawSimplePrompt pStr
|
{ promptDrawer = drawSimplePrompt pStr
|
||||||
, promptCharCheck = const True
|
, promptProcessChar = \ch -> (++ [ch])
|
||||||
, promptAction = act
|
, promptAction = act
|
||||||
, promptSpecialKey = const $ return ()
|
, promptSpecialKey = const $ return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Creates an upper case string prompt
|
||||||
|
ucStrPrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (String -> Action ())
|
||||||
|
-- ^ The callback function for the result
|
||||||
|
-> Prompt
|
||||||
|
ucStrPrompt pStr act = (ucStrPrompt pStr act)
|
||||||
|
{ promptProcessChar = \ch -> (++ [toUpper ch]) }
|
||||||
|
|
||||||
-- | Builds a numeric prompt
|
-- | Builds a numeric prompt
|
||||||
numPrompt
|
numPrompt
|
||||||
:: String
|
:: String
|
||||||
|
@ -126,7 +135,9 @@ numPrompt
|
||||||
-> Prompt
|
-> Prompt
|
||||||
numPrompt pStr act = Prompt
|
numPrompt pStr act = Prompt
|
||||||
{ promptDrawer = drawSimplePrompt pStr
|
{ promptDrawer = drawSimplePrompt pStr
|
||||||
, promptCharCheck = isDigit
|
, promptProcessChar = \ch str -> if isDigit ch
|
||||||
|
then str ++ [ch]
|
||||||
|
else str
|
||||||
, promptAction = \inStr -> forM_ (readMaybe inStr) act
|
, promptAction = \inStr -> forM_ (readMaybe inStr) act
|
||||||
, promptSpecialKey = const $ return ()
|
, promptSpecialKey = const $ return ()
|
||||||
}
|
}
|
||||||
|
@ -146,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
|
||||||
, promptCharCheck = const True
|
, promptProcessChar = \ch -> (++[ch])
|
||||||
, promptAction = \sStr -> if null sStr
|
, promptAction = \sStr -> if null sStr
|
||||||
then spCallback params Nothing
|
then spCallback params Nothing
|
||||||
else do
|
else do
|
||||||
|
|
|
@ -601,8 +601,8 @@ instance ToJSON GameStats where
|
||||||
data Prompt = Prompt
|
data Prompt = Prompt
|
||||||
{ promptDrawer :: ProgState -> C.Update ()
|
{ promptDrawer :: ProgState -> C.Update ()
|
||||||
-- ^ Draws the prompt to the screen
|
-- ^ Draws the prompt to the screen
|
||||||
, promptCharCheck :: Char -> Bool
|
, promptProcessChar :: Char -> String -> String
|
||||||
-- ^ Determines whether or not the character is valid
|
-- ^ Modifies the string based on the character entered
|
||||||
, promptAction :: String -> Action ()
|
, promptAction :: String -> Action ()
|
||||||
-- ^ Action to perform when the value is entered
|
-- ^ Action to perform when the value is entered
|
||||||
, promptSpecialKey :: C.Key -> Action ()
|
, promptSpecialKey :: C.Key -> Action ()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user