2020-08-04 17:36:31 +02:00
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
module Main where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Options.Applicative
|
|
|
|
import Data.Semigroup ((<>))
|
|
|
|
|
2020-08-06 00:30:25 +02:00
|
|
|
import qualified Transforms
|
|
|
|
import qualified Keyboard
|
|
|
|
import qualified App
|
2020-08-04 17:36:31 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data CommandArgs = CommandArgs
|
2020-08-06 00:30:25 +02:00
|
|
|
{ transforms :: String
|
2020-08-06 01:18:44 +02:00
|
|
|
, passage :: String
|
2020-08-04 17:36:31 +02:00
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
|
|
|
parseArgs :: Parser CommandArgs
|
|
|
|
parseArgs =
|
|
|
|
CommandArgs <$> strOption
|
2020-08-06 00:30:25 +02:00
|
|
|
( long "transforms"
|
|
|
|
<> short 't'
|
|
|
|
<> help "String of transforms where (e.g. \"HHVS12VHVHS3\")" )
|
2020-08-06 01:18:44 +02:00
|
|
|
<*> strOption
|
|
|
|
( long "passage"
|
|
|
|
<> short 'p'
|
|
|
|
<> help "Input text to re-type" )
|
2020-08-04 17:36:31 +02:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2020-08-06 00:30:25 +02:00
|
|
|
CommandArgs{..} <- execParser opts
|
|
|
|
case Transforms.fromString transforms of
|
|
|
|
Nothing -> putStrLn "You must provide valid input (e.g. \"HHVS12VHVHS3\")"
|
2020-08-06 01:18:44 +02:00
|
|
|
Just xs -> do
|
|
|
|
let keyboard = foldl App.transform Keyboard.qwerty (Transforms.optimize xs)
|
|
|
|
putStrLn $ "Typing: \"" ++ passage ++ "\"\nOn this keyboard:\n" ++ show keyboard
|
|
|
|
case App.retypePassage passage keyboard of
|
|
|
|
Nothing -> putStrLn $ "Looks like at least one of the characters in your input passage doesn't fit on our QWERTY keyboard: \n" ++ show Keyboard.qwerty
|
|
|
|
Just result -> putStrLn $ "Result: " ++ result
|
2020-08-04 17:36:31 +02:00
|
|
|
where
|
|
|
|
opts = info (parseArgs <**> helper)
|
|
|
|
( fullDesc
|
2020-08-06 00:30:25 +02:00
|
|
|
<> progDesc "Transform a QWERTY keyboard using a string of commands")
|