Skip to content

Commit

Permalink
Use simpler ‘\r’ instead of cursor manipulation escape sequences
Browse files Browse the repository at this point in the history
This primarily benefits displaying progress in Emacs’s shell-mode
since it supports \r but doesn’t support ansi escapes other than
color manipulation ones.
  • Loading branch information
sergv authored and Bodigrim committed Dec 8, 2023
1 parent 1147251 commit f124f67
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ buildTestOutput opts tree =
name
(replicate postNamePadding ' ')

resultPosition = length testNamePadded

printTestName = do
putStr testNamePadded
hFlush stdout
Expand All @@ -171,11 +169,12 @@ buildTestOutput opts tree =
("", pct) -> printf "%.0f%% " pct
(txt, 0.0) -> printf "%s" txt
(txt, pct) -> printf "%s: %.0f%% " txt pct
setCursorColumn resultPosition
infoOk msg
putChar '\r'
-- A new progress message may be shorter than the previous one
-- so we must clean until the end of the line
clearFromCursorToLineEnd
-- so we must clean whole line and print anew.
clearLine
putStr testNamePadded
infoOk msg
hFlush stdout

printTestResult result = do
Expand All @@ -191,8 +190,9 @@ buildTestOutput opts tree =
time = resultTime result

when getAnsiTricks $ do
setCursorColumn resultPosition
clearFromCursorToLineEnd
putChar '\r'
clearLine
putStr testNamePadded

printFn (resultShortDescription result)
when (floor (time * 1e6) >= minDurationMicros) $
Expand Down

0 comments on commit f124f67

Please sign in to comment.