Prompting for a password in Haskell command line application

前端 未结 6 957
傲寒
傲寒 2021-02-01 04:10

The following Haskell program prompts the user for a password in the terminal and continues if he has entered the correct one:

main = do
    putStrLn \"Password:         


        
6条回答
  •  梦谈多话
    2021-02-01 04:15

    withEcho can be written with a little less noise:

    withEcho :: Bool -> IO a -> IO a
    withEcho echo action =
        bracket (hGetEcho stdin)
                (hSetEcho stdin)
                (const $ hSetEcho stdin echo >> action)
    

提交回复
热议问题