urbit/pkg/hs/urbit-king/lib/Urbit/Vere/Term/API.hs

45 lines
1011 B
Haskell
Raw Normal View History

2020-01-23 07:16:09 +03:00
{-|
Interface Terminal API.
-}
module Urbit.Vere.Term.API (Ev(..), Client(..), trace, spin, stopSpin) where
import Urbit.Prelude hiding (trace)
import Urbit.Arvo (Belt, Blit)
-- External Types --------------------------------------------------------------
2020-01-23 07:16:09 +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
| Blank
2019-09-18 09:58:42 +03:00
| Spinr (Maybe (Maybe Cord))
deriving (Show)
data Client = Client
{ take :: STM (Maybe Belt)
, give :: [Ev] -> STM ()
}
2019-09-18 09:58:42 +03:00
deriveNoun ''Ev
-- Utilities -------------------------------------------------------------------
trace :: Client -> Text -> STM ()
trace ts = give ts . singleton . Trace . Cord
spin :: Client -> Maybe Text -> STM ()
spin ts = give ts . singleton . Spinr . Just . fmap Cord
stopSpin :: Client -> STM ()
stopSpin ts = give ts [Spinr Nothing]