From 9c8238e475f6e45a8a0a1ce25e2d004a1c525d80 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 5 Jan 2018 12:41:01 +0000 Subject: [PATCH] Add help command Also changed all occurrences of "InputT IO" to "Input". --- app/Main.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index b5d9023..534c3e4 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -88,7 +88,7 @@ askCountdown time l@((key, card):xs) = do -- because they use the prompt functions. -- Print out info about a card when asking it -askCardWithInfo :: UTCTime -> Card -> Int -> MaybeT (InputT IO) Card +askCardWithInfo :: UTCTime -> Card -> Int -> MaybeT Input Card askCardWithInfo time card left = do let t = rjust ' ' 9 $ tierName $ tier card l = rjust ' ' 3 $ show left @@ -98,7 +98,7 @@ askCardWithInfo time card left = do -- Ask the sides on a card and reset or update the card accordingly -- Doesn't check whether the card is due or not. -askCard :: UTCTime -> Card -> MaybeT (InputT IO) Card +askCard :: UTCTime -> Card -> MaybeT Input Card askCard time card = do (_, unasked) <- spanM askSide $ sides card mapM_ showSide $ drop 1 unasked @@ -123,15 +123,23 @@ displaySide side = lift (putStrLn side) - User prompt. -} -learn :: Elements -> InputT IO Elements +learn :: Elements -> Input Elements learn elms = do time <- lift $ getCurrentTime askElements time elms -stats :: Elements -> InputT IO () +stats :: Elements -> Input () stats = undefined -- TODO: Use tierName -run :: Elements -> InputT IO Elements +help :: Input () +help = do + outputStrLn " List of commands:" + outputStrLn "h, help -> display this help" + outputStrLn "l, learn -> start revising cards (press ctrl+D to exit)" + outputStrLn "q, quit -> exit program" + outputStrLn "s, show -> show how many cards are in which tiers" + +run :: Elements -> Input Elements run elms = do cmd <- getInputLine "%> " let logCmd command = modifyHistory $ addHistoryUnlessConsecutiveDupe command @@ -144,8 +152,10 @@ run elms = do Just "l" -> logCmd "learn" >> learn elms >>= run Just "show" -> logCmd "show" >> stats elms >> run elms Just "s" -> logCmd "show" >> stats elms >> run elms + Just "help" -> logCmd "help" >> help >> run elms + Just "h" -> logCmd "help" >> help >> run elms Just x -> do - outputStrLn $ "Unknown command " ++ show x ++ "." + outputStrLn $ "Unknown command " ++ show x ++ ". Try \"help\" for a list of commands." run elms -- Maybe save cards?