From a068b7e6d7dc970d471db772227a416e4e38b711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 27 Aug 2017 11:18:18 +0200 Subject: [PATCH] game: avoid a terminal glitch when showing the state --- src/game.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index b94331a..de3ba5a 100644 --- a/src/game.c +++ b/src/game.c @@ -307,6 +307,10 @@ static void end(struct oshu_game *game) * * Only do that for terminal outputs in order not to spam something if the * output is redirected. + * + * The state length must not decrease over time, otherwise you end up with + * glitches. If you write `foo\rx`, you get `xoo`. This is the reason the + * Paused string literal has an extra space. */ static void dump_state(struct oshu_game *game, double now) { @@ -314,7 +318,7 @@ static void dump_state(struct oshu_game *game, double now) return; int minutes = (int) now / 60.; double seconds = now - (minutes * 60.); - const char *state = game->paused ? "Paused": "Playing"; + const char *state = game->paused ? " Paused" : "Playing"; printf("%s: %d:%06.3f\r", state, minutes, seconds); fflush(stdout); }