Terminal gets ruined after using charterm

I'm trying to use charterm to build a roguelike. I'm using iTerm2 with zsh on a mac. After exiting my racket program, terminal outputs every new line indented starting at the end of the previous line, like this:

$ ls -1
actions
       input.rkt
                level.rkt
                         loop.rkt
                                 pos.rkt
                                        render
                                              %

Those are actual spaces and the % sign at the end is also added to every output. Here's a screenshot:

If I pipe that into less, the output looks normal for what that's worth.

This isn't a huge deal but it is kind of annoying. Anybody know what's going on?

Here's the screen drawing code: rkt/roguelike/engine/render/term.rkt at main · mskoh52/rkt · GitHub

I modified charterm to use utf-8 instead of latin-8 but this issue appeared before I did that as well.

You’re probably missing some cleanup exit sequences. Try running the command reset to fix the terminal.

rkt/roguelike/engine/loop.rkt at main · mskoh52/rkt · GitHub is the source of your problem. The dynamic-wind inside charterm - rkt/roguelike/engine/render/charterm.rkt at main · mskoh52/rkt · GitHub - doesn't get the chance to run close-charterm which would perform the necessary cleanup.

I would use (void) instead of (exit) in your particular case.

That did the trick, thank you!