Is there a norm or standard width for Gnu-Linux/Unix-terminals?
I have to create an application which writes a big amount of text in different Gnu-Linux/Unix-terminals.开发者_StackOverflow中文版 Is there a norm or standard width I could refer to? I mean like in the world of web-design where they use 1024 Pixel width as a rule of thumb.
Thanks for your time.
Traditionally, the 80 character limit, (meaning that lines longer than 80 characters are wrapped to the next line), has been the norm. However, there has been discussion about the relevancy of this standard, (see here). In my University experience, however, we were taught that comfortable viewing in a terminal is 80 characters. If you are using the default 12pt monospaced font for linux, this would mean that a good width would be approximately 80 * the width of one character. A better solution would probably be to simply cut off each line at 80 chars programmatically.
tldr: 80 characters
Programs can obtain the terminal width and height from the terminal driver using the ioctl()
system call with the TIOCGWINSZ
request code. If that's not available, defaulting to 80 seems sensible.
For example:
#include <sys/ioctl.h>
int get_term_width(void) {
struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) >= 0)
return ws.ws_col;
else
return 80;
}
80 cols and 24 was the old VT200 standard, that was kept for a long time.
With today's graphical monitors, you can't adhere to that, but there's other means. Take a look at ncurses. It is a function set of positioning text on the console, no matter if it is re-sized, etc. Weechat and Irssi are prominent users of ncurses.
In brief, 80 characters.
That's been a sort of de-facto standard since, well, since punched cards actually.
精彩评论