<commit_before>{-# LANGUAGE Arrows #-}

import Control.Wire
import Prelude hiding ((.), id)
import System.Console.ANSI
import Data.Maybe
import Control.Arrow
import Control.Monad.Trans.State
import Control.Monad.Trans
import Data.Time.Clock
import GHC.Conc

deltaClockSession dt =
    Session $ do
        t0 <- liftIO getCurrentTime
        return (0, loop t0)
    where
    loop t' =
        Session $ do
            threadDelay dt
            t <- liftIO getCurrentTime
            let realdt = realToFrac (diffUTCTime t t')
            return (realdt, loop t)

control whenInhibited whenProduced wire = loop wire (deltaClockSession 10000)
   where
     loop w' session' = do
         (mx, w, session) <- stepSession w' session' ()
         case mx of
           Left ex -> whenInhibited ex
           Right x -> whenProduced x
         loop w session `catch` (\_ ->  ansiFinishUI)

ansiFinishUI = do
    scrollPageUp 1
    setCursorPosition 24 0
    showCursor


impure f = mkFixM $ \_ x -> Right <$> f x
showW :: (Show a) => WireM IO a a
showW = impure (\x -> putStrLn (show x) >> return x )
clearScreenW = impure (\x -> clearScreen >> return x)
moveCursorW = impure (\(x, y) -> setCursorPosition y x >> return (x, y))

foreign import ccall unsafe "conio.h getch" c_getch :: IO Char
foreign import ccall unsafe "conio.h kbhit" c_kbhit :: IO Bool<commit_msg>fixed types<commit_after>{-# LANGUAGE Arrows #-}
-- https://gist.github.com/danbst/4676502
import Control.Wire
import Control.Exception
import Prelude hiding ((.), id)
import System.Console.ANSI
import Data.Maybe
import Control.Arrow
import Control.Monad.Trans.State
import Control.Monad.Trans
import Data.Time.Clock
import GHC.Conc

deltaClockSession dt =
    Session $ do
        t0 <- liftIO getCurrentTime
        return (0, loop t0)
    where
    loop t' =
        Session $ do
            threadDelay dt
            t <- liftIO getCurrentTime
            let realdt = realToFrac (diffUTCTime t t')
            return (realdt, loop t)

control whenInhibited whenProduced wire = loop wire (deltaClockSession 10000)
   where
     loop w' session' = do
         (mx, w, session) <- stepSession w' session' ()
         case mx of
           Left ex -> whenInhibited ex
           Right x -> whenProduced x
         loop w session `catch` ((\_ ->  ansiFinishUI) :: SomeException -> IO ())

ansiFinishUI = do
    scrollPageUp 1
    setCursorPosition 24 0
    showCursor


impure f = mkFixM $ \_ x -> Right <$> f x
showW :: (Show a) => WireM IO a a
showW = impure (\x -> putStrLn (show x) >> return x )
clearScreenW = impure (\x -> clearScreen >> return x)
moveCursorW = impure (\(x, y) -> setCursorPosition y x >> return (x, y))

foreign import ccall unsafe "conio.h getch" c_getch :: IO Char
foreign import ccall unsafe "conio.h kbhit" c_kbhit :: IO Bool
{'fraction_non_alphanumeric': 0.09943181818181818, 'fraction_numerical': 0.011008522727272728, 'mean_word_length': 2.5839694656488548, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2063756', 'n_tokens_mistral': 935, 'n_tokens_neox': 890, 'n_words': 311}