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

42 lines
928 B
Haskell
Raw Normal View History

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
| Blank
2019-09-18 09:58:42 +03:00
| Spinr (Maybe (Maybe Cord))
deriving (Show)
data Client = Client
{ take :: STM Belt
, give :: Ev -> STM ()
}
2019-09-18 09:58:42 +03:00
deriveNoun ''Ev
-- Utilities -------------------------------------------------------------------
trace :: Client -> Text -> STM ()
2019-09-18 09:58:42 +03:00
trace ts = give ts . Trace . Cord
spin :: Client -> Maybe Text -> STM ()
2019-09-18 09:58:42 +03:00
spin ts = give ts . Spinr . Just . fmap Cord
stopSpin :: Client -> STM ()
stopSpin ts = give ts (Spinr Nothing)