module System.Console.Haskeline.Term where
import System.Console.Haskeline.Monads
import System.Console.Haskeline.LineState
import System.Console.Haskeline.Command
import Control.Concurrent
import Control.Concurrent.STM
class MonadIO m => Term m where
withReposition :: Layout -> m a -> m a
moveToNextLine :: LineState s => s -> m ()
printLines :: [String] -> m ()
drawLineDiff :: (LineState s, LineState r)
=> String -> s -> r -> m ()
clearLayout :: m ()
ringBell :: Bool -> m ()
data RunTerm m = forall t . (Term (t m), MonadTrans t) => RunTerm {
getLayout :: IO Layout,
withGetEvent :: forall a . Bool -> (t m Event -> t m a) -> t m a,
runTerm :: forall a . t m a -> m a,
putStrTerm :: String -> IO ()
}
matchInit :: Eq a => [a] -> [a] -> ([a],[a])
matchInit (x:xs) (y:ys) | x == y = matchInit xs ys
matchInit xs ys = (xs,ys)
keyEventLoop :: (TChan Event -> IO ()) -> TChan Event -> IO Event
keyEventLoop readKey eventChan = do
me <- atomically $ tryReadTChan eventChan
case me of
Just e -> return e
Nothing -> do
tid <- forkIO (readKey eventChan)
e <- atomically $ readTChan eventChan
killThread tid
return e
tryReadTChan :: TChan a -> STM (Maybe a)
tryReadTChan chan = fmap Just (readTChan chan) `orElse` return Nothing
class (MonadReader Layout m, MonadIO m) => MonadLayout m where