Monadoro-0.2.1.0: src/Clock.lhs
#!/usr/bin/env stack
> --stack --install-ghc runghc --package markdown-unlit -- "-pgmL markdown-unlit"
> {-# LANGUAGE OverloadedStrings #-}
This is a simple countdown clock module.
> module Clock (countdown) where
> import Control.Concurrent (threadDelay)
> import System.Console.ANSI (clearLine,
> clearFromCursorToScreenEnd,
> setCursorColumn,
> hideCursor,
> showCursor,
> saveCursor,
> restoreCursor)
> import System.Environment (getArgs)
> import System.IO (hFlush,
> stdout)
> import Timer (secToTimestamp)
>
> -- >>> putStrLn "Hello world!"
> -- Hello world!
> --
> -- >>> putStrLn "Test complete!"
> -- Test complete!
> countdown :: IO()
> countdown = do
> wait_seconds $ 25 * 60 + 1
> wait_seconds :: Int -> IO()
> wait_seconds 0 = do
> putStrLn ""
> wait_seconds n = do
> putStr ""
> setCursorColumn 0
> putStr $ secToTimestamp $ n - 1
> hFlush stdout
> delay 1
> wait_seconds $ n - 1
> delay :: Int -> IO()
> delay n = del n
>
> del :: Int -> IO()
> del n = do
> threadDelay $ n * 1000 * 1000
>
> no_del :: Int -> IO()
> no_del n = do
> return ()
>
> main :: IO()
> main = do
> countdown