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