Permalink
Browse files

Started tapiPass prompt

  • Loading branch information...
1 parent b6da9fb commit b0184d05763b59975f47b15c221f1d26083f6ae9 @Detegr committed Mar 1, 2014
Showing with 37 additions and 15 deletions.
  1. +35 −13 src/TapiPass.hs
  2. +1 −1 src/YubiKey.hs
  3. +1 −1 tapiPass.cabal
View
@@ -2,27 +2,49 @@
module Main where
-import qualified Data.HashTable.ST.Basic as HT
-import Control.Monad.ST.Safe
-import Data.Text
+import Prelude hiding (words)
+import qualified Data.Map as Map
+import Control.Monad
+import Control.Monad.IO.Class (liftIO)
+import Control.Monad.Trans.State
+import Data.Text.Lazy
import Data.Maybe (fromMaybe)
-import qualified Data.Text.IO as TIO
+import qualified Data.Text.Lazy.IO as TIO
import Control.Monad.Trans.Error (runErrorT)
+import Control.Monad (forever)
+import System.IO
import YubiKey
-{-
-hashTest :: ST s Text
-hashTest = do
- ht <- HT.new :: ST s (HT.HashTable s Text Text)
- HT.insert ht "key" "val"
- mb <- HT.lookup ht "key"
- return $ fromMaybe "nothing" mb
--}
+type TapiPass a = StateT TPState IO a
+type TPState = (Maybe YubiKey, Map.Map Text Text)
+
+printPromptGetLine :: IO Text
+printPromptGetLine = do
+ TIO.putStr promptStr
+ hFlush stdout
+ TIO.getLine
+
+tapiPassPrompt :: TapiPass Text
+tapiPassPrompt = liftIO printPromptGetLine >>= exec
+
+exec :: Text -> TapiPass Text
+exec args = do
+ (_,map) <- get
+ let arglist = words args
+ return $ case Prelude.head arglist of
+ "list" -> pack . show $ map
+ _ -> "Invalid command"
+
+promptStr :: Text
+promptStr = ">> "
main :: IO()
-main = do
+main = forever $ evalStateT tapiPassPrompt (Nothing, Map.empty) >>= TIO.putStrLn
+
+{-
ok <- runErrorT $ withYubiKey $ \_ -> putStrLn "YubiKey found"
case ok of
Right _ -> putStrLn "YubiKey was found and function ran correctly"
Left err -> putStrLn $ "Error: " ++ err
+-}
View
@@ -1,6 +1,6 @@
{-# LANGUAGE ForeignFunctionInterface #-}
-module YubiKey(withYubiKey) where
+module YubiKey(withYubiKey, YubiKey) where
import Foreign.C.String
import Foreign.C.Types
View
@@ -20,7 +20,7 @@ executable tapiPass
main-is: TapiPass.hs
other-modules: YubiKey
-- other-extensions:
- build-depends: base >=4.5, hashtables >= 1.1.2.1, text, transformers, hashable
+ build-depends: base >=4.5, hashtables >= 1.1.2.1, text, transformers, containers, control-monad-loop
hs-source-dirs: src
default-language: Haskell2010
extra-libraries: ykpers-1

0 comments on commit b0184d0

Please sign in to comment.