blob: f655d0a8a3407a727cc51b7b3bea7527e421d6d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-- All console output in keysafe should go via this module;
-- avoid using putStrLn, print, etc directly.
module Output (ask, progress, say, warn, display) where
import System.IO
import Data.Char
ask :: String -> IO ()
ask s = do
putStr (escape s)
hFlush stdout
progress :: String -> IO ()
progress = ask
say :: String -> IO ()
say = putStrLn . escape
warn :: String -> IO ()
warn = hPutStrLn stderr . escape
display :: Show s => s -> IO ()
display = say . show
-- | Prevent malicious escape sequences etc in a string
-- from being output to the console.
escape :: String -> String
escape = concatMap go
where
go c = if isPrint c || isSpace c
then [c]
else "\\" ++ show (ord c)
|