The border drawing functions just don't seem to draw the top and bottom borders properly when the window's width is above 8. As a disclaimer, I'm using KiTTY to SSH into an Arch Linux server.
I'm a newbie to ncurses, so there's a good chance I'm doing something wrong, but from what I've read this should be right...
#include <ncurses.h>
int main() {
initscr(); cbreak();
WINDOW *win = newwin(1,1, 1,1);
for(int i=1; i < 16; ++i) {
wresize(win, i, i);
wclear(win);
box(win, 0,0); // I've also tested wborder()
wrefresh(win);
mvprintw(0,0, "size: %i", i);
getch(); //pause
}
endwin();
return 0;
}
Running this code, this is what I see:
size: 8
+------+
¦ ¦ Displays like this (normally)
¦ ¦ for both top and bottom borders
¦ ¦
¦ ¦
¦ ¦
¦ ¦
+------+
size: 9
+-+
¦ ¦ Each size up it will continue
¦ ¦ to look like this, with the
¦ ¦ top and bottom borders looking
¦ ¦ like `+-+`
¦ ¦
¦ ¦
¦ ¦
+-+
ncurses uses a terminal capability database to get information about terminal control sequences that a terminal supports. It uses the value of the TERM
environment variable to look up this information. PuTTY or KiTTY passes a desired value of the TERM
environment variable to the SSH server. Often it is set to "xterm" by default, but it can be changed in the session settings under Connection -> Data -> Terminal-type string.
PuTTY and KiTTY used to support the control sequences for "xterm" in the terminal capability database quite well, but recent (mid-2017 onwards) versions of the database optimized the sequences defined for "xterm" to use sequences not currently supported by PuTTY or KiTTY. Specifically, it now makes use of the ECMA-48 REP (repeat character) control sequence which is not supported by PuTTY. To make line drawing work properly on systems with a recent terminal capability database, the TERM
environment variable needs to be changed for PuTTY or KiTTY. (It can be changed in the session settings as discussed above.) Suitable values for recent versions of the terminal capability database include "putty" or "putty-256color". The value "xterm-old" may also work.
Check the "/usr/share/terminfo" directory on your host system to see which terminal types are actually defined by the system. The first letter of the terminal type is split off as a subdirectory so that, for example, the terminal capabilities for the "putty" terminal type are defined by the "/usr/share/terminfo/p/putty" file.
Note that this problem affects not only line-drawing, but any horizontal repeats of the same character more than six times. It is addressed by the ncurses FAQ:
That only covers the features which are in the terminal description, and does not address differences between terminal emulators. For example, in mid-2017, an update to the xterm terminal description added the ECMA-48 REP (repeat character) control. It was part of xterm since January 1997, but a terminal description using the feature was part of xterm only (not ncurses). After adding it to ncurses, it was observed that:
- rxvt is unaffected, since it does not use
TERM=xterm
.
- mlterm and OSX Terminal supported REP, using
TERM=xterm
.
- VTE, konsole, PuTTY, iTerm2 did not support this standard, longstanding feature, of xterm although they set
TERM
to xterm
or xterm-256color
.
- screen and tmux use a different
TERM
setting, and seemed to work (although tmux had some other issue with the test).