2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
|
|
|
Interface Terminal API.
|
|
|
|
-}
|
2020-01-24 08:28:38 +03:00
|
|
|
module Urbit.Vere.Term.API (Ev(..), Client(..), trace, spin, stopSpin) where
|
2019-09-18 08:22:19 +03:00
|
|
|
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Prelude hiding (trace)
|
2019-09-18 08:22:19 +03:00
|
|
|
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Arvo (Belt, Blit)
|
2019-09-18 08:22:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- External Types --------------------------------------------------------------
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-09-18 08:22:19 +03:00
|
|
|
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
|
2019-12-17 21:06:20 +03:00
|
|
|
{ take :: STM (Maybe 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]
|