#!/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 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 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" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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 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] = forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> String -> IO String
countdownLoop IO ()
withDelay String
s)
parse [String]
_ = 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 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [String] -> IO ()
parse