From 08da90e893c14760cbfe41baaafa3683769f7110 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 14 Nov 2025 16:21:02 -0500 Subject: Fix cursor movement to avoid updating wrong lines - Remove save/restore cursor in favor of explicit movement - Always move up from bottom position, update line, move back down - Simplify initializeLines to just print lines sequentially - Cursor now stays at bottom and moves up/down for each update - Fixes issue where lines were being updated far up the terminal --- Omni/Log/Concurrent.hs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'Omni/Log') diff --git a/Omni/Log/Concurrent.hs b/Omni/Log/Concurrent.hs index 4654365..86a3853 100644 --- a/Omni/Log/Concurrent.hs +++ b/Omni/Log/Concurrent.hs @@ -88,15 +88,12 @@ initializeLines :: LineManager -> IO () initializeLines LineManager {..} = when lmSupportsANSI <| do nsMap <- readIORef namespaceLines - forM_ (Map.toList nsMap) <| \(ns, lineNum) -> do - ANSI.hSaveCursor IO.stderr + forM_ (Map.toList nsMap) <| \(ns, _) -> do ANSI.hSetCursorColumn IO.stderr 0 - when (lineNum > 0) <| ANSI.hCursorDown IO.stderr lineNum ANSI.hClearLine IO.stderr let nsText = Text.pack (Namespace.toPath ns) - IO.hPutStr IO.stderr (Text.unpack <| "[…] " <> nsText) + IO.hPutStrLn IO.stderr (Text.unpack <| "[…] " <> nsText) IO.hFlush IO.stderr - ANSI.hRestoreCursor IO.stderr updateLine :: Namespace -> Text -> IO () updateLine ns output = do @@ -115,15 +112,17 @@ updateLine ns output = do case Map.lookup ns nsMap of Nothing -> pure () Just lineNum -> do - ANSI.hSaveCursor IO.stderr + let numLines = length lmNamespaces + -- Move to the target line from bottom + ANSI.hCursorUp IO.stderr (numLines - lineNum) ANSI.hSetCursorColumn IO.stderr 0 - ANSI.hCursorUp IO.stderr (length lmNamespaces - lineNum) ANSI.hClearLine IO.stderr let nsText = Text.pack (Namespace.toPath ns) let formattedOutput = if Text.null output then "[~] " <> nsText else "[~] " <> nsText <> ": " <> output IO.hPutStr IO.stderr (Text.unpack formattedOutput) IO.hFlush IO.stderr - ANSI.hRestoreCursor IO.stderr + -- Move back to bottom + ANSI.hCursorDown IO.stderr (numLines - lineNum) updateLineState :: Namespace -> BuildState -> IO () updateLineState ns buildState = do @@ -136,9 +135,10 @@ updateLineState ns buildState = do case Map.lookup ns nsMap of Nothing -> pure () Just lineNum -> do - ANSI.hSaveCursor IO.stderr + let numLines = length lmNamespaces + -- Move to the target line from bottom + ANSI.hCursorUp IO.stderr (numLines - lineNum) ANSI.hSetCursorColumn IO.stderr 0 - ANSI.hCursorUp IO.stderr (length lmNamespaces - lineNum) ANSI.hClearLine IO.stderr let nsText = Text.pack (Namespace.toPath ns) case buildState of @@ -151,4 +151,5 @@ updateLineState ns buildState = do Building -> IO.hPutStr IO.stderr (Text.unpack <| "[~] " <> nsText) IO.hFlush IO.stderr - ANSI.hRestoreCursor IO.stderr + -- Move back to bottom + ANSI.hCursorDown IO.stderr (numLines - lineNum) -- cgit v1.2.3