diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-14 16:15:03 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-14 16:15:03 -0500 |
| commit | c9a63966191d6959ee2759d56fb31798bc19c26b (patch) | |
| tree | aacdb3934895a4a2f5166a65991999c62cb10c05 | |
| parent | 77f836754cf63bcd8f44dfbf1f8305277700554c (diff) | |
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
| -rw-r--r-- | Omni/Log/Concurrent.hs | 12 |
1 files changed, 3 insertions, 9 deletions
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 |
