avoid cursor jitter when updating progress display

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
This commit is contained in:
Joey Hess 2021-10-07 10:58:49 -04:00
parent e9b0cf08eb
commit 1c11dd4793
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 7 additions and 4 deletions

View file

@ -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

View 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