2019-09-18 08:22:19 +03:00
|
|
|
module Vere.Term.API (Ev(..), Client(..), trace, spin, stopSpin) where
|
|
|
|
|
|
|
|
import UrbitPrelude hiding (trace)
|
|
|
|
|
|
|
|
import Arvo (Blit, Belt)
|
|
|
|
|
|
|
|
|
|
|
|
-- External Types --------------------------------------------------------------
|
|
|
|
|
|
|
|
{-
|
|
|
|
Input Event for terminal driver:
|
|
|
|
|
|
|
|
%blits -- list of blits from arvo.
|
|
|
|
%trace -- stderr line from runtime.
|
|
|
|
%blank -- print a blank line
|
|
|
|
%spinr -- Start or stop the spinner
|
|
|
|
-}
|
|
|
|
data Ev = Blits [Blit]
|
2019-09-18 09:58:42 +03:00
|
|
|
| Trace Cord
|
2019-09-18 08:22:19 +03:00
|
|
|
| Blank
|
2019-09-18 09:58:42 +03:00
|
|
|
| Spinr (Maybe (Maybe Cord))
|
|
|
|
deriving (Show)
|
2019-09-18 08:22:19 +03:00
|
|
|
|
|
|
|
data Client = Client
|
|
|
|
{ take :: STM Belt
|
2019-09-18 12:11:18 +03:00
|
|
|
, give :: [Ev] -> STM ()
|
2019-09-18 08:22:19 +03:00
|
|
|
}
|
|
|
|
|
2019-09-18 09:58:42 +03:00
|
|
|
deriveNoun ''Ev
|
|
|
|
|
2019-09-18 08:22:19 +03:00
|
|
|
|
|
|
|
-- Utilities -------------------------------------------------------------------
|
|
|
|
|
|
|
|
trace :: Client -> Text -> STM ()
|
2019-09-18 12:11:18 +03:00
|
|
|
trace ts = give ts . singleton . Trace . Cord
|
2019-09-18 08:22:19 +03:00
|
|
|
|
|
|
|
spin :: Client -> Maybe Text -> STM ()
|
2019-09-18 12:11:18 +03:00
|
|
|
spin ts = give ts . singleton . Spinr . Just . fmap Cord
|
2019-09-18 08:22:19 +03:00
|
|
|
|
|
|
|
stopSpin :: Client -> STM ()
|
2019-09-18 12:11:18 +03:00
|
|
|
stopSpin ts = give ts [Spinr Nothing]
|