From f124f6749dac27410c80ceb7a1cf39e459ea9484 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Sun, 1 Oct 2023 19:43:34 +0100 Subject: [PATCH] =?UTF-8?q?Use=20simpler=20=E2=80=98\r=E2=80=99=20instead?= =?UTF-8?q?=20of=20cursor=20manipulation=20escape=20sequences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- core/Test/Tasty/Ingredients/ConsoleReporter.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/Test/Tasty/Ingredients/ConsoleReporter.hs b/core/Test/Tasty/Ingredients/ConsoleReporter.hs index 09af2002..10693242 100644 --- a/core/Test/Tasty/Ingredients/ConsoleReporter.hs +++ b/core/Test/Tasty/Ingredients/ConsoleReporter.hs @@ -152,8 +152,6 @@ buildTestOutput opts tree = name (replicate postNamePadding ' ') - resultPosition = length testNamePadded - printTestName = do putStr testNamePadded hFlush stdout @@ -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 @@ -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) $