I'd like to add an output formatting enhancement to a C language open source command line terminal application.
The application does not place the console into any sort of raw mode, it just uses printf to stdout. I'd like to format the output a little better, but this requires knowing the current width of the console (and reacting when the width changes). The code includes termios (#include <termios.h>) if it's present, but does not make any real use of it. Nothing like ncurses is present in the code at all.
The application must remain fully cross-platform compatible, and not break when used over an ssh or telnet session. So I'm seeking an answer with an eye to all the gotchas that can come up with terminal width detection.
Again, all I need is the width. If the width is unavailable, I can fall back to the present assumption that the terminal is infinitely wide. If the width changes during execution, I must find out.
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----
Keywords: detect, sense, terminal, console, display size, width, wide, columns, output formatting, alternative, TERMIOS.TIOCGWINSZ, without curses, without ncurses, echo $COLUMNS, Linux, Unix, Solaris, cross-platform, generic unix, open source.
Start Free Trial