From 2b2ea59fc9fa0ff5bb17251cc9345391346021a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 4 Jun 2024 22:24:24 +0200 Subject: Quit command --- README.md | 6 ++++++ main/Main.hs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 85b2f88..3248b6f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ followed by command name and parameters (if any) separated by spaces. When a conversation is selected, message to send there is entered directly on the command prompt. +The session can be terminated either by end-of-input (typically `Ctrl-d`) or +using the `/quit` command. + ### Messaging `/peers` @@ -132,6 +135,9 @@ re-established by either side. `/update-identity` Interactively update current identity information +`/quit` +Quit the erebos tool. + Storage ------- diff --git a/main/Main.hs b/main/Main.hs index df904a2..ca980ca 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -292,9 +292,12 @@ interactiveLoop st opts = runInputT inputSettings $ do , ciSetContextOptions = \ctxs -> liftIO $ modifyMVar_ contextOptions $ const $ return ctxs } case res of - Right cstate' -> return cstate' - Left err -> do lift $ lift $ extPrint $ "Error: " ++ err - return cstate + Right cstate' + | csQuit cstate' -> mzero + | otherwise -> return cstate' + Left err -> do + lift $ lift $ extPrint $ "Error: " ++ err + return cstate let loop (Just cstate) = runMaybeT (process cstate) >>= loop loop Nothing = return () @@ -305,6 +308,7 @@ interactiveLoop st opts = runInputT inputSettings $ do , csIceSessions = [] #endif , csIcePeer = Nothing + , csQuit = False } @@ -324,6 +328,7 @@ data CommandState = CommandState , csIceSessions :: [IceSession] #endif , csIcePeer :: Maybe Peer + , csQuit :: Bool } data CommandContext = NoContext @@ -399,6 +404,7 @@ commands = , ("ice-connect", cmdIceConnect) , ("ice-send", cmdIceSend) #endif + , ("quit", cmdQuit) ] commandCompletion :: CompletionFunc IO @@ -649,3 +655,6 @@ cmdIceSend = void $ do liftIO $ serverPeerIce server s #endif + +cmdQuit :: Command +cmdQuit = modify $ \s -> s { csQuit = True } -- cgit v1.2.3