Append only commands to command history

This commit is contained in:
Joscha 2018-01-05 00:22:26 +00:00
parent 81adcb6111
commit 5bbc069013

View file

@ -9,6 +9,7 @@ import Control.Monad.Trans.Maybe
import Data.Char import Data.Char
import Data.Time import Data.Time
import System.Console.Haskeline import System.Console.Haskeline
import System.Console.Haskeline.History
type Input = InputT IO type Input = InputT IO
@ -16,7 +17,7 @@ inputSettings :: Settings IO
inputSettings = Settings inputSettings = Settings
{ complete = noCompletion { complete = noCompletion
, historyFile = Nothing , historyFile = Nothing
, autoAddHistory = True , autoAddHistory = False
} }
{- {-
@ -133,15 +134,16 @@ stats = undefined -- TODO: Use tierName
run :: Elements -> InputT IO Elements run :: Elements -> InputT IO Elements
run elms = do run elms = do
cmd <- getInputLine "%> " cmd <- getInputLine "%> "
let logCmd command = modifyHistory $ addHistoryUnlessConsecutiveDupe command
case trim ' ' . map toLower <$> cmd of case trim ' ' . map toLower <$> cmd of
Nothing -> return elms Nothing -> return elms
Just "" -> run elms Just "" -> run elms
Just "quit" -> return elms Just "quit" -> logCmd "quit" >> return elms
Just "q" -> return elms Just "q" -> logCmd "quit" >> return elms
Just "learn" -> learn elms >>= run Just "learn" -> logCmd "learn" >> learn elms >>= run
Just "l" -> learn elms >>= run Just "l" -> logCmd "learn" >> learn elms >>= run
Just "show" -> stats elms >> run elms Just "show" -> logCmd "show" >> stats elms >> run elms
Just "s" -> stats elms >> run elms Just "s" -> logCmd "show" >> stats elms >> run elms
Just x -> do Just x -> do
outputStrLn $ "Unknown command " ++ show x ++ "." outputStrLn $ "Unknown command " ++ show x ++ "."
run elms run elms