Skip to content

Commit

Permalink
game: avoid a terminal glitch when showing the state
Browse files Browse the repository at this point in the history
  • Loading branch information
fmang committed Aug 27, 2017
1 parent 5101aa1 commit a068b7e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,18 @@ 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)
{
if (!isatty(fileno(stdout)))
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);
}
Expand Down

0 comments on commit a068b7e

Please sign in to comment.