8

I am trying to learn ncurses to add some functionality to my programs however I cannot seem to get my terminal settings to the point where the default ncurses window border shows up as expected.

Here is the output I am getting for a window with a box border:

  lqqqqqqqqk
  x        x
  x        x
  x        x
  mqqqqqqqqj

However I should be getting this:

  ┌────────┐
  │        │
  │        │
  │        │
  └────────┘

The only thing I am able to find that fixes this issue is setting my PuTTY Remove Character Set to be Latin-1 instead of UTF-8, however this messes up all of my other applications including VIM.

There were some related SO questions that I found (1 and 2) however neither of their solutions help me. The only interesting thing I pulled out of the second one is that if I run printf '\342\224\224\342\224\200\342\224\220' in my command line it prints out └─┐ (which is correct...).

Here is the simple program I am using to test this:

 #include <iostream>
 #include <ncurses.h>
 #include <string>
 #include <cstring>

 int main() {
     WINDOW *my_win;
     int startx, starty, width, height;
     int ch;

     initscr();
     cbreak();
     keypad(stdscr, TRUE);
     refresh();

     int height = 5;
     int width = 10;
     my_win = newwin(height, width, 1, 2);
     box(my_win, 0, 0);
     wrefresh(my_win);

     getch();

     endwin();
     return 0;
 }

Any ideas what I could be doing wrong? Thanks!

Community
  • 1
  • 1
wakey
  • 2,283
  • 4
  • 31
  • 58
  • 2
    You need to check the documentation for whatever terminal program you're using, and pick the right `TERM` setting. That's it. – Sam Varshavchik Dec 30 '16 at 01:47
  • I am using PuTTY with ubuntu and my `TERM` is export `xterm-256color`. From what I understand that shouldn't be the issue... – wakey Dec 30 '16 at 01:50
  • And I also have `export NCURSES_NO_UTF8_ACS=1` in my `.bashrc` – wakey Dec 30 '16 at 01:51
  • A brief Google search suggests that "putty-256color" is the correct `TERM` setting. – Sam Varshavchik Dec 30 '16 at 01:53
  • I remember running into that when I was doing my troubleshooting - it does not fix the issue – wakey Dec 30 '16 at 01:56
  • What happens if you unset `NCURSES_NO_UTF8_ACS`? – Keith Thompson Dec 30 '16 at 02:26
  • No change after I unset it :/ – wakey Dec 30 '16 at 02:46
  • Do either `wborder()` with wide-character values, or `wborder_set()` with UTF-8 strings, work for you? Are you compiling with and linking to an up-to-date ncurses lib that supports UTF-8? Is your locale environment variable set? Also, you’re not running something in 7-bit mode, are you? – Davislor Dec 30 '16 at 08:09

2 Answers2

8

You're not initializing the locale. Without that, ncurses will assume that it can use the terminal description.

Further reading:

The library uses the locale which the calling program has initialized. That is normally done with setlocale:

setlocale(LC_ALL, "");

If the locale is not initialized, the library assumes that characters are printable as in ISO-8859-1, to work with certain legacy programs. You should initialize the locale and not rely on specific details of the library when the locale has not been setup.

During initialization, the ncurses library checks for special cases where VT100 line-drawing (and the corresponding alternate character set capabilities) described in the terminfo are known to be missing. Specifically, when running in a UTF-8 locale, the Linux console emulator and the GNU screen program ignore these. Ncurses checks the TERM environment variable for these. For other special cases, you should set this environment variable.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
2

A solution would be in putty configuration to make sure to check "Enable VT100 line drawing even in UTF-8 mode".

Putty Screenshot

dwf981
  • 21
  • 2