avoid cursor jitter when updating progress display
authorJoey Hess <joeyh@joeyh.name>
Thu, 7 Oct 2021 14:58:49 +0000 (10:58 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 7 Oct 2021 15:16:41 +0000 (11:16 -0400)
When the progress display gets longer, and then shorter again, it causes
the cursor to jitter back and forth. Somehow I never noticed this until
this morning, but then it became intolerable to watch.

To fix it, pad the progress display to the maximum length it's occupied.

Sponsored-by: Svenne Krap on Patreon
CHANGELOG
Utility/Metered.hs

index 25e9e7ace189cf15b0708aea745fd39ad308ae5a..a66d4524d1490f07e46ae38a53222ca0846529f8 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -16,6 +16,7 @@ git-annex (8.20210904) UNRELEASED; urgency=medium
   * reinject: Fix crash when reinjecting a file from outside the repository.
     (Reversion in version 8.20210621)
   * borg: Some improvements to memory use when importing a lot of archives.
+  * Avoid cursor jitter when updating progress display.
 
  -- Joey Hess <id@joeyh.name>  Fri, 03 Sep 2021 12:02:55 -0400
 
index 21c9cd84552e00d38985928d4ff032da7be487fd..8fd9c9b6675d8e96adb03b52a4ad6c46ccc7f9e5 100644 (file)
@@ -459,12 +459,14 @@ updateMeter (Meter totalsizev sv bv displaymeter) new = do
 -- | Display meter to a Handle.
 displayMeterHandle :: Handle -> RenderMeter -> DisplayMeter
 displayMeterHandle h rendermeter v msize old new = do
+       olds <- takeMVar v
        let s = rendermeter msize old new
-       olds <- swapMVar v s
+       let padding = replicate (length olds - length s) ' '
+       let s' = s <> padding
+       putMVar v s'
        -- Avoid writing when the rendered meter has not changed.
-       when (olds /= s) $ do
-               let padding = replicate (length olds - length s) ' '
-               hPutStr h ('\r':s ++ padding)
+       when (olds /= s') $ do
+               hPutStr h ('\r':s')
                hFlush h
 
 -- | Clear meter displayed by displayMeterHandle. May be called before