Make king shutdown cleanly on a new line.
This makes canceling the persistance thread not rethrow an exception
which kills the process, and makes the terminal driver write one
final newline before giving control back to the terminal so the
bash prompt writes to its own line.
@@ -55,6 +55,7 @@ data TerminalSystem e = TerminalSystem
data Private = Private
{ pReaderThread :: Async ()
, pWriterThread :: Async ()
+ , pTerminal :: Terminal
, pPreviousConfiguration :: TerminalAttributes
}
@@ -101,11 +102,11 @@ initializeLocalTerminal = do
start = do
-- Initialize the writing side of the terminal
--
- t <- io $ setupTermFromEnv
+ pTerminal <- io $ setupTermFromEnv
-- TODO: We still need to actually get the size from the terminal somehow.
tsWriteQueue <- newTQueueIO
- pWriterThread <- asyncBound (writeTerminal t tsWriteQueue)
+ pWriterThread <- asyncBound (writeTerminal pTerminal tsWriteQueue)
pPreviousConfiguration <- io $ getTerminalAttributes stdInput
@@ -134,8 +135,11 @@ initializeLocalTerminal = do
-- can't kill. If we were to cancel here, the internal `waitCatch` would
-- block until the next piece of keyboard input. Since this only happens
-- at shutdown, just leak the file descriptor.
-
cancel pWriterThread
+
+ -- inject one final newline, as we're usually on the prompt.
+ io $ runTermOutput pTerminal $ termText "\r\n"
+
-- take the terminal out of raw mode
io $ setTerminalAttributes stdInput pPreviousConfiguration Immediately
@@ -356,15 +360,12 @@ term TerminalSystem{..} shutdownSTM pierPath king enqueueEv =
runTerm :: RAcquire e (EffCb e TermEf)
runTerm = do
- tim <- mkRAcquire start stop
+ tim <- mkRAcquire start cancel
pure handleEffect
start :: RIO e (Async ())
start = async readBelt
- stop :: Async () -> RIO e ()
- stop rb = cancel rb
-
readBelt :: RIO e ()
readBelt = forever $ do
b <- atomically $ readTQueue tsReadQueue
