From c9a63966191d6959ee2759d56fb31798bc19c26b Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 14 Nov 2025 16:15:03 -0500 Subject: Fix cursor positioning to preserve shell prompt - Use hCursorDown in initializeLines instead of hCursorUp - Simplify updateLine and updateLineState cursor movement - Cursor now moves up from bottom position correctly - Shell prompt no longer gets erased --- Omni/Log/Concurrent.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'Omni') diff --git a/Omni/Log/Concurrent.hs b/Omni/Log/Concurrent.hs index d7723e5..4654365 100644 --- a/Omni/Log/Concurrent.hs +++ b/Omni/Log/Concurrent.hs @@ -91,7 +91,7 @@ initializeLines LineManager {..} = forM_ (Map.toList nsMap) <| \(ns, lineNum) -> do ANSI.hSaveCursor IO.stderr ANSI.hSetCursorColumn IO.stderr 0 - ANSI.hCursorUp IO.stderr (length lmNamespaces - lineNum) + 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) @@ -117,10 +117,7 @@ updateLine ns output = do Just lineNum -> do ANSI.hSaveCursor IO.stderr ANSI.hSetCursorColumn IO.stderr 0 - let currentLine = length lmNamespaces - let linesToMove = currentLine - lineNum - when (linesToMove > 0) <| ANSI.hCursorUp IO.stderr linesToMove - when (linesToMove < 0) <| ANSI.hCursorDown IO.stderr (abs linesToMove) + 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 @@ -141,10 +138,7 @@ updateLineState ns buildState = do Just lineNum -> do ANSI.hSaveCursor IO.stderr ANSI.hSetCursorColumn IO.stderr 0 - let currentLine = length lmNamespaces - let linesToMove = currentLine - lineNum - when (linesToMove > 0) <| ANSI.hCursorUp IO.stderr linesToMove - when (linesToMove < 0) <| ANSI.hCursorDown IO.stderr (abs linesToMove) + ANSI.hCursorUp IO.stderr (length lmNamespaces - lineNum) ANSI.hClearLine IO.stderr let nsText = Text.pack (Namespace.toPath ns) case buildState of -- cgit v1.2.3