git-annex/Types/Messages.hs

87 lines
2.3 KiB
Haskell
Raw Normal View History

{- git-annex Messages data types
-
- Copyright 2012-2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Types.Messages where
import qualified Utility.Aeson as Aeson
import Utility.Metered
2015-04-03 23:56:56 +00:00
import Control.Concurrent
import System.Console.Regions (ConsoleRegion)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
data OutputType
= NormalOutput
| QuietOutput
| JSONOutput JSONOptions
| SerializedOutput
(SerializedOutput -> IO ())
(IO (Maybe SerializedOutputResponse))
data JSONOptions = JSONOptions
{ jsonProgress :: Bool
, jsonErrorMessages :: Bool
}
deriving (Show)
adjustOutputType :: OutputType -> OutputType -> OutputType
adjustOutputType (JSONOutput old) (JSONOutput new) = JSONOutput $ JSONOptions
{ jsonProgress = jsonProgress old || jsonProgress new
, jsonErrorMessages = jsonErrorMessages old || jsonErrorMessages new
}
adjustOutputType _old new = new
data SideActionBlock = NoBlock | StartBlock | InBlock
deriving (Eq)
data MessageState = MessageState
{ outputType :: OutputType
, concurrentOutputEnabled :: Bool
, sideActionBlock :: SideActionBlock
, consoleRegion :: Maybe ConsoleRegion
, consoleRegionErrFlag :: Bool
, jsonBuffer :: Maybe Aeson.Object
, promptLock :: MVar () -- left full when not prompting
, clearProgressMeter :: IO ()
}
newMessageState :: IO MessageState
newMessageState = do
promptlock <- newMVar ()
return $ MessageState
2015-11-06 16:51:25 +00:00
{ outputType = NormalOutput
, concurrentOutputEnabled = False
2015-11-06 16:51:25 +00:00
, sideActionBlock = NoBlock
, consoleRegion = Nothing
, consoleRegionErrFlag = False
, jsonBuffer = Nothing
, promptLock = promptlock
, clearProgressMeter = return ()
2015-11-06 16:51:25 +00:00
}
2020-12-03 18:57:22 +00:00
-- | When communicating with a child process over a pipe while it is
-- performing some action, this is used to pass back output that the child
-- would normally display to the console.
data SerializedOutput
= OutputMessage S.ByteString
| OutputError String
2020-12-11 16:52:22 +00:00
| BeginProgressMeter
| UpdateProgressMeterTotalSize TotalSize
2020-12-11 16:52:22 +00:00
| UpdateProgressMeter BytesProcessed
| EndProgressMeter
| BeginPrompt
| EndPrompt
| JSONObject L.ByteString
2020-12-03 18:57:22 +00:00
-- ^ This is always sent, it's up to the consumer to decide if it
-- wants to display JSON, or human-readable messages.
deriving (Show)
data SerializedOutputResponse
= ReadyPrompt
deriving (Eq, Show)