#!/usr/bin/env stack
module CountdownLoop (countdown, countdownLoop) where
import System.Environment (getArgs)
import Control.Concurrent (threadDelay)
import Control.Monad (void)
import ParseTime (count_down_time)
import Display (display)
milisecPerSecond :: Int
milisecPerSecond :: Int
milisecPerSecond = Int
10 Int -> Int -> Int
forall a b. (Num a, Integral b) => a -> b -> a
^ (Int
6 :: Int)
wait :: Int -> IO()
wait :: Int -> IO ()
wait Int
n = Int -> IO ()
threadDelay (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
milisecPerSecond)
withDelay :: IO()
withDelay :: IO ()
withDelay = Int -> IO ()
wait Int
1
noDelay :: IO()
noDelay :: IO ()
noDelay = Int -> IO ()
wait Int
0
countdown :: String -> IO String
countdown :: String -> IO String
countdown = IO () -> String -> IO String
countdownLoop IO ()
withDelay
countdownLoop :: IO() -> String -> IO String
countdownLoop :: IO () -> String -> IO String
countdownLoop IO ()
delayer String
"00:00" = String -> IO ()
display String
"00:00" IO () -> IO String -> IO String
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
"00:00"
countdownLoop IO ()
delayer String
s = do
String -> IO ()
display String
s
IO ()
delayer
(IO () -> String -> IO String
countdownLoop IO ()
delayer (String -> IO String) -> (String -> String) -> String -> IO String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
count_down_time) String
s
parse :: [String] -> IO ()
parse :: [String] -> IO ()
parse [String
s] = IO String -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> String -> IO String
countdownLoop IO ()
withDelay String
s)
parse [String]
_ = IO String -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> String -> IO String
countdownLoop IO ()
withDelay String
"00:00")
main :: IO ()
main :: IO ()
main = IO [String]
getArgs IO [String] -> ([String] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [String] -> IO ()
parse