使用 UTF-8 和 PuTTY 时,NCURSES 边框打印为 q、x
NCURSES border printing as q, x, when using UTF-8 and PuTTY
我正在尝试学习 ncurses 以向我的程序添加一些功能,但是我似乎无法将我的终端设置设置为默认 ncurses window 边框按预期显示的程度。
这是我为带框边框的 window 获得的输出:
lqqqqqqqqk
x x
x x
x x
mqqqqqqqqj
但是我应该得到这个:
┌────────┐
│ │
│ │
│ │
└────────┘
我唯一能找到解决这个问题的方法是将我的 PuTTY 删除字符集设置为 Latin-1 而不是 UTF-8,但这会弄乱我的所有其他应用程序,包括 VIM .
我发现了一些相关的 SO 问题 (1 and 2),但是他们的解决方案都没有帮助我。我从第二个中取出的唯一有趣的事情是,如果我在我的命令行中 运行 printf '244240240'
它打印出 └─┐
(这是正确的......)。
这是我用来测试的简单程序:
#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;
}
知道我可能做错了什么吗?谢谢!
您没有初始化语言环境。否则,ncurses 将假设它可以使用终端描述。
进一步阅读:
- ncurses 手册页,Initialization:
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.
- ncurses 手册页,
NCURSES_NO_UTF8_ACS
:
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.
一个解决方案是在 putty 配置中确保选中“即使在 UTF-8 模式下也启用 VT100 线条图”。
Putty Screenshot
我正在尝试学习 ncurses 以向我的程序添加一些功能,但是我似乎无法将我的终端设置设置为默认 ncurses window 边框按预期显示的程度。
这是我为带框边框的 window 获得的输出:
lqqqqqqqqk
x x
x x
x x
mqqqqqqqqj
但是我应该得到这个:
┌────────┐
│ │
│ │
│ │
└────────┘
我唯一能找到解决这个问题的方法是将我的 PuTTY 删除字符集设置为 Latin-1 而不是 UTF-8,但这会弄乱我的所有其他应用程序,包括 VIM .
我发现了一些相关的 SO 问题 (1 and 2),但是他们的解决方案都没有帮助我。我从第二个中取出的唯一有趣的事情是,如果我在我的命令行中 运行 printf '244240240'
它打印出 └─┐
(这是正确的......)。
这是我用来测试的简单程序:
#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;
}
知道我可能做错了什么吗?谢谢!
您没有初始化语言环境。否则,ncurses 将假设它可以使用终端描述。
进一步阅读:
- ncurses 手册页,Initialization:
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.
- ncurses 手册页,
NCURSES_NO_UTF8_ACS
:
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.
一个解决方案是在 putty 配置中确保选中“即使在 UTF-8 模式下也启用 VT100 线条图”。
Putty Screenshot