mirror of
https://github.com/redelmann/scat
synced 2025-01-10 06:34:20 +01:00
Added ANSI output formating and Android lock pattern.
This commit is contained in:
parent
344755342b
commit
1b15288135
30
src/Scat.hs
30
src/Scat.hs
@ -4,8 +4,7 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString, unpack)
|
||||||
import Data.ByteString (unpack)
|
|
||||||
import qualified Data.ByteString.Char8 as C
|
import qualified Data.ByteString.Char8 as C
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Exit
|
import System.Exit
|
||||||
@ -60,7 +59,19 @@ scat = do
|
|||||||
pw <- getPassword
|
pw <- getPassword
|
||||||
c <- getCode
|
c <- getCode
|
||||||
printVerbose "Generated password:\n"
|
printVerbose "Generated password:\n"
|
||||||
liftIO $ putStrLn $ evalBuilder s $ scatter k pw c
|
showGenerated $ evalBuilder s $ scatter k pw c
|
||||||
|
|
||||||
|
-- | Prints out the generated password.
|
||||||
|
showGenerated :: String -> Scat ()
|
||||||
|
showGenerated gen = do
|
||||||
|
v <- fmap verbose ask
|
||||||
|
a <- fmap ansi ask
|
||||||
|
let ok = v && a
|
||||||
|
liftIO $ do
|
||||||
|
when ok $ setSGR [SetSwapForegroundBackground True]
|
||||||
|
putStrLn gen
|
||||||
|
when ok $ setSGR [SetSwapForegroundBackground False]
|
||||||
|
|
||||||
|
|
||||||
-- | Prints, if the verbosity level allows it.
|
-- | Prints, if the verbosity level allows it.
|
||||||
printVerbose :: String -> Scat ()
|
printVerbose :: String -> Scat ()
|
||||||
@ -106,7 +117,8 @@ prompt vis str = do
|
|||||||
(hSetEcho stdin old)
|
(hSetEcho stdin old)
|
||||||
C.getLine
|
C.getLine
|
||||||
v <- fmap verbose ask
|
v <- fmap verbose ask
|
||||||
when (shouldErase vis && v) $ liftIO $ do
|
a <- fmap ansi ask
|
||||||
|
when (shouldErase vis && a && v) $ liftIO $ do
|
||||||
cursorUpLine 1
|
cursorUpLine 1
|
||||||
cursorForward $ length str
|
cursorForward $ length str
|
||||||
clearFromCursorToScreenEnd
|
clearFromCursorToScreenEnd
|
||||||
@ -151,6 +163,16 @@ getSchema = do
|
|||||||
-- PIN.
|
-- PIN.
|
||||||
'p' : 'i' : 'n' : xs | [(n, "")] <- reads xs -> return $ pin n
|
'p' : 'i' : 'n' : xs | [(n, "")] <- reads xs -> return $ pin n
|
||||||
|
|
||||||
|
-- PIN with default size.
|
||||||
|
"pin" -> return $ pin 6
|
||||||
|
|
||||||
|
-- Pattern lock
|
||||||
|
'l' : 'o' : 'c' : 'k' : xs | [(n, "")] <- reads xs -> return $
|
||||||
|
androidPatternLock n
|
||||||
|
|
||||||
|
-- Default size of pattern lock
|
||||||
|
"lock" -> return $ androidPatternLock 9
|
||||||
|
|
||||||
-- Passphrase using Diceware's list.
|
-- Passphrase using Diceware's list.
|
||||||
"diceware" -> liftIO diceware
|
"diceware" -> liftIO diceware
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user