summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-11-14 16:21:02 -0500
committerBen Sima <ben@bsima.me>2025-11-14 16:21:02 -0500
commit08da90e893c14760cbfe41baaafa3683769f7110 (patch)
tree89bb608ffb791efadbb22f2d193cf0e6399a9f54 /Omni
parentc9a63966191d6959ee2759d56fb31798bc19c26b (diff)
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
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Log/Concurrent.hs23
1 files changed, 12 insertions, 11 deletions
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)