1
1
mirror of https://github.com/Yvee1/hascard.git synced 2024-10-26 07:41:15 +03:00

Add multiple answer possibilities for each gap

This commit is contained in:
Steven van den Broek 2020-07-18 14:28:24 +02:00
parent 898e79d5b0
commit faaf372441
5 changed files with 12 additions and 29 deletions

View File

@ -22,16 +22,4 @@ Explanation or definition of this word, or the answer to the question.
# Fill in the gaps
The symbol € is for the currency named _Euro_, and is used in the _EU|European Union_.
---
word = synonym
---
word = short explanation
---
word = translation of word
---
---

View File

@ -365,7 +365,7 @@ handleEvent s (VtyEvent ev) = case ev of
sentence = perforatedToSentence perforated
gaps = sentenceToGaps sentence
s' = s & (cardState.correctGaps) %~ M.mapWithKey (\i _ -> gaps !! i == M.findWithDefault "" i kvs) & (cardState.entered) .~ True
s' = s & (cardState.correctGaps) %~ M.mapWithKey (\i _ -> M.findWithDefault "" i kvs `elem` gaps !! i) & (cardState.entered) .~ True
-- correct = M.foldr (&&) True (s' ^. (cardState.correctGaps))
-- use above if you want to go to next card directly, if gaps were filled in correctly
correct = M.foldr (&&) True cGaps

View File

@ -55,9 +55,6 @@ theMap = attrMap V.defAttr
, (errorAttr, fg V.red)
]
-- drawUI :: FileBrowser Name -> [Widget Name]
-- drawUI b = [renderFileBrowser True b]
drawUI :: State -> [Widget Name]
drawUI State{_fb=b, _exception=exc} = [center $ ui <=> help]
where
@ -77,10 +74,7 @@ drawUI State{_fb=b, _exception=exc} = [center $ ui <=> help]
, hCenter $ txt "Esc: quit"
]
handleEvent :: State -> BrickEvent Name Event -> EventM Name (Next (State))
-- handleEvent s (VtyEvent (V.EvKey V.KEsc [])) = halt s
-- handleEvent s (VtyEvent ev) = do fb'<- handleFileBrowserEvent ev (s ^. fb)
-- continue $ s & fb .~ fb'
handleEvent :: State -> BrickEvent Name Event -> EventM Name (Next State)
handleEvent s@State{_fb=b} (VtyEvent ev) =
case ev of
V.EvKey V.KEsc [] | not (fileBrowserIsSearching b) ->

View File

@ -87,11 +87,12 @@ pPerforated = do
pGap = do
pre <- manyTill anyChar $ lookAhead (try gappedSpecialChars)
char '_'
gap <- manyTill (noneOf "_") $ lookAhead (try gappedSpecialChars)
gaps <- manyTill (noneOf "_|") (lookAhead (try gappedSpecialChars)) `sepBy1` string "|"
char '_'
return (pre, gap)
return (pre, NE.fromList gaps)
gappedSpecialChars = seperator
<|> string "|"
<|> string "_"
pNormal = do

View File

@ -25,8 +25,8 @@ newtype IncorrectOption = IncorrectOption String
data Option = Option Type String
deriving Show
-- Pre Gap Post
data Sentence = Perforated String String Sentence
-- Pre Gap Post
data Sentence = Perforated String (NonEmpty String) Sentence
| Normal String
deriving Show
@ -35,17 +35,17 @@ nGapsInSentence = nGapsInSentence' 0
nGapsInSentence' acc (Normal s) = acc
nGapsInSentence' acc (Perforated pre gap post) = nGapsInSentence' (1+acc) post
foldSentence :: (String -> a) -> (String -> String -> a -> a) -> Sentence -> a
foldSentence :: (String -> a) -> (String -> NonEmpty String -> a -> a) -> Sentence -> a
foldSentence norm perf = f where
f (Normal text) = norm text
f (Perforated pre gap sent) = perf pre gap (f sent)
foldSentenceIndex :: (String -> Int -> a) -> (String -> String -> a -> Int -> a) -> Sentence -> a
foldSentenceIndex :: (String -> Int -> a) -> (String -> NonEmpty String -> a -> Int -> a) -> Sentence -> a
foldSentenceIndex norm perf = f 0 where
f i (Normal text) = norm text i
f i (Perforated pre gap sent) = perf pre gap (f (i+1) sent) i
data Perforated = P String String Sentence
data Perforated = P String (NonEmpty String) Sentence
deriving Show
perforatedToSentence :: Perforated -> Sentence
@ -54,5 +54,5 @@ perforatedToSentence (P pre gap sentence) = Perforated pre gap sentence
nGapsInPerforated :: Perforated -> Int
nGapsInPerforated = nGapsInSentence . perforatedToSentence
sentenceToGaps :: Sentence -> [String]
sentenceToGaps :: Sentence -> [NonEmpty String]
sentenceToGaps = foldSentence (const []) (\_ gap acc -> gap : acc)