command-line-interfacewindow-resizeansi-escapetermios

resizable box-drawing in the terminal


I'm currently trying to do pretty cli apps, my goal is to make a box that makes the whole outline of the terminal.

What I currently do:

And I put all this in a loop and refresh it 30 times per second. The problem is that when the terminal is resized, some edges are offset and displayed in the middle of the screen for a small amount of time.

How can you avoid these small glitches ? Is it possible to tell the terminal to not display anything while the user is resizing or something like that ?

Thanks in advance


Solution

  • The question:

    How can you avoid these small glitches ? Is it possible to tell the terminal to not display anything while the user is resizing or something like that ?

    You can't entirely avoid that. Applications which deal with window-resizing catch SIGWINCH (rather than relying on repeatedly checking the size), and repaint the screen. If that is "fast enough", it is not really noticeable.

    When catching SIGWINCH, it is also possible for those to arrive too frequently to respond to each one. An application has to allow for that (by omitting repainting when it starts to fall behind).