simplify transferr protocol
This commit is contained in:
parent
095cdc7e83
commit
0c46ee5ce0
4 changed files with 16 additions and 17 deletions
|
@ -116,7 +116,10 @@ metered' st othermeter msize showoutput a = go st
|
|||
a meter (combinemeter m)
|
||||
| otherwise = nometer
|
||||
go (MessageState { outputType = SerializedOutput h _ }) = do
|
||||
liftIO $ outputSerialized h $ BeginProgressMeter msize
|
||||
liftIO $ outputSerialized h BeginProgressMeter
|
||||
case msize of
|
||||
Just sz -> liftIO $ outputSerialized h $ UpdateProgressMeterTotalSize sz
|
||||
Nothing -> noop
|
||||
szv <- liftIO $ newIORef msize
|
||||
meter <- liftIO $ mkMeter msize $ \_ msize' _old new -> do
|
||||
case msize' of
|
||||
|
|
|
@ -63,11 +63,11 @@ relaySerializedOutput getso sendsor meterreport runannex = go Nothing
|
|||
outputSerialized h $ JSONObject b
|
||||
_ -> q
|
||||
loop st
|
||||
Left (BeginProgressMeter sz) -> do
|
||||
Left BeginProgressMeter -> do
|
||||
ost <- runannex (Annex.getState Annex.output)
|
||||
-- Display a progress meter while running, until
|
||||
-- the meter ends or a final value is returned.
|
||||
metered' ost Nothing sz (runannex showOutput)
|
||||
metered' ost Nothing Nothing (runannex showOutput)
|
||||
(\meter meterupdate -> loop (Just (meter, meterupdate)))
|
||||
>>= \case
|
||||
Right r -> return (Right r)
|
||||
|
|
|
@ -68,9 +68,9 @@ newMessageState = do
|
|||
data SerializedOutput
|
||||
= OutputMessage S.ByteString
|
||||
| OutputError String
|
||||
| BeginProgressMeter (Maybe TotalSize)
|
||||
| UpdateProgressMeter BytesProcessed
|
||||
| BeginProgressMeter
|
||||
| UpdateProgressMeterTotalSize TotalSize
|
||||
| UpdateProgressMeter BytesProcessed
|
||||
| EndProgressMeter
|
||||
| BeginPrompt
|
||||
| EndPrompt
|
||||
|
|
|
@ -85,14 +85,12 @@ instance Proto.Sendable TransferResponse where
|
|||
["om", Proto.serialize (encode_c (decodeBS m))]
|
||||
formatMessage (TransferOutput (OutputError e)) =
|
||||
["oe", Proto.serialize (encode_c e)]
|
||||
formatMessage (TransferOutput (BeginProgressMeter (Just (TotalSize n)))) =
|
||||
["opb", Proto.serialize n]
|
||||
formatMessage (TransferOutput (BeginProgressMeter Nothing)) =
|
||||
["opbx"]
|
||||
formatMessage (TransferOutput (UpdateProgressMeter n)) =
|
||||
["op", Proto.serialize n]
|
||||
formatMessage (TransferOutput BeginProgressMeter) =
|
||||
["opb"]
|
||||
formatMessage (TransferOutput (UpdateProgressMeterTotalSize (TotalSize sz))) =
|
||||
["ops", Proto.serialize sz]
|
||||
formatMessage (TransferOutput (UpdateProgressMeter n)) =
|
||||
["op", Proto.serialize n]
|
||||
formatMessage (TransferOutput EndProgressMeter) =
|
||||
["ope"]
|
||||
formatMessage (TransferOutput BeginPrompt) =
|
||||
|
@ -111,14 +109,12 @@ instance Proto.Receivable TransferResponse where
|
|||
TransferOutput . OutputMessage . encodeBS . decode_c
|
||||
parseCommand "oe" = Proto.parse1 $
|
||||
TransferOutput . OutputError . decode_c
|
||||
parseCommand "opb" = Proto.parse1 $
|
||||
TransferOutput . BeginProgressMeter . Just . TotalSize
|
||||
parseCommand "opbx" = Proto.parse0 $
|
||||
TransferOutput (BeginProgressMeter Nothing)
|
||||
parseCommand "op" = Proto.parse1 $
|
||||
TransferOutput . UpdateProgressMeter
|
||||
parseCommand "opb" = Proto.parse0 $
|
||||
TransferOutput BeginProgressMeter
|
||||
parseCommand "ops" = Proto.parse1 $
|
||||
TransferOutput . UpdateProgressMeterTotalSize . TotalSize
|
||||
parseCommand "op" = Proto.parse1 $
|
||||
TransferOutput . UpdateProgressMeter
|
||||
parseCommand "ope" = Proto.parse0 $
|
||||
TransferOutput EndProgressMeter
|
||||
parseCommand "oprb" = Proto.parse0 $
|
||||
|
|
Loading…
Reference in a new issue