ncurses在OSX上不显示的A_ALTCHARSET字符

时间:2016-02-29 00:03:13

标签: c++ linux macos ncurses

我在c ++程序中使用ncurses并希望能够使用A_ALTCHARSET字符。在我的linux计算机上它工作正常但是当我在我的Mac上尝试它时,几个字符显示为'?'。作为测试,我在两台计算机上运行this website的第二个程序。在我的linux计算机上,它正确地显示了所有字符并显示了与网站上的图片相同的内容,但在我的Mac上我得到了:

                                NCURSES ALTCHARSET CHARACTERS
     43 = > │  44 = < │  45 = ^ │  46 = v │  48 = # │  96 = ◆ │  97 = ▒ │ 102 = °
    103 = ± │ 104 = # │ 105 = ␋ │ 106 = ┘ │ 107 = ┐ │ 108 = ┌ │ 109 = └ │ 110 = ┼
    111 = ⎺ │ 112 = ⎻ │ 113 = ─ │ 114 = ⎼ │ 115 = ⎽ │ 116 = ├ │ 117 = ┤ │ 118 = ┴
    119 = ┬ │ 120 = │ │ 121 = ≤ │ 122 = ≥ │ 123 = π │ 124 = ≠ │ 125 = £ │ 126 = ·
    128 = ? │ 161 = ? │ 162 = ? │ 163 = ? │ 164 = ? │ 165 = ? │ 166 = ? │ 167 = ?
    168 = ? │ 169 = ? │ 170 = ? │ 171 = ? │ 172 = ? │ 174 = ? │ 175 = ? │ 176 = ?
    177 = ? │ 178 = ? │ 179 = ? │ 180 = ? │ 181 = ? │ 182 = ? │ 183 = ? │ 184 = ?
    185 = ? │ 186 = ? │ 187 = ? │ 188 = ? │ 189 = ? │ 190 = ? │ 191 = ? │ 192 = ?
    193 = ? │ 194 = ? │ 195 = ? │ 196 = ? │ 197 = ? │ 198 = ? │ 199 = ? │ 200 = ?
    201 = ? │ 202 = ? │ 203 = ? │ 204 = ? │ 205 = ? │ 206 = ? │ 207 = ? │ 208 = ?
    209 = ? │ 210 = ? │ 211 = ? │ 212 = ? │ 213 = ? │ 214 = ? │ 215 = ? │ 216 = ?
    217 = ? │ 218 = ? │ 219 = ? │ 220 = ? │ 221 = ? │ 222 = ? │ 223 = ? │ 224 = ?
    225 = ? │ 226 = ? │ 227 = ? │ 228 = ? │ 229 = ? │ 230 = ? │ 231 = ? │ 232 = ?
    233 = ? │ 234 = ? │ 235 = ? │ 236 = ? │ 237 = ? │ 238 = ? │ 239 = ? │ 240 = ?
    241 = ? │ 242 = ? │ 243 = ? │ 244 = ? │ 245 = ? │ 246 = ? │ 247 = ? │ 248 = ?
    249 = ? │ 250 = ? │ 251 = ? │ 252 = ? │ 253 = ? │ 254 = ? │ 255 = ? │ 

为什么这不起作用,是否需要解决它?

2 个答案:

答案 0 :(得分:0)

看起来好像您将TERM设置为linux。 Linux控制台提供了一种非VT100方法来绘制线图形(主要使用160-255的代码)。 OSX终端实现了VT100风格的线图,需要切换字符集。如屏幕截图所示, linux 不是您使用终端首选项设置的设置之一。但是,人们在.bashrc等中设置变量并不罕见:

showing available terminfo entries assumed by Apple

终端描述(由TERM环境变量选择)在此区域中有所不同。 OSX终端的推荐TERM是ncurses中 nsterm 的一种。比较:

$ infocmp linux nsterm |grep acs
        acsc: '+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376', '``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~'.
        enacs: NULL, '\E(B\E)0'.
        rmacs: '\E[10m', '^O'.
        smacs: '\E[11m', '^N'.

VT100风格功能中的smacsrmacs字符串称为 shift-in shift-out (对于正常和图形)。正如您所看到的,他们并不喜欢Linux功能。

进一步阅读:

要查找的功能是程序在shell中使用的TERM的值。 OSX终端只有一种可能的行为(无匹配&#34; linux&#34;)。该程序确实有一个首选项对话框设置TERM,虽然你的shell可能明确地将它设置为其他值。 例如,终端数据库注意到

# * The terminal preferences dialog replaces xterm-color by xterm-16color and
#   xterm-256color.  However, it adds "nsterm", so it is possible to use the
#   nsterm entry from this file to override the MacPorts (20110404) or
#   system (20081102) copy of this file.
# + In OS X 10.8 (Mountain Lion) the TERM which can be set in the preferences
#   dialog defaults to xterm-256color.  Alternative selections are ansi,
#   dtterm, rxvt, vt52, vt100, vt102, xterm and xterm-16color.  However,
#   the menu says "Declare terminal as" without promising to actually emulate
#   the corresponding terminals.  Indeed, changing TERM does not affect the

上述内容于2016年2月撰写.ncurses和Linux的开发正在进行中。在May 2016中,这种变化是针对ncurses&#39;终端数据库:

# 2016-05-14
#       + modify linux2.6 entry to improve line-drawing -TD
#       + make linux3.0 entry the default linux entry (Debian #823658) -TD

这使得标准 linux 终端说明在此区域看起来更像 nsterm 。如果您在最新的系统上运行 infocmp ,则不会看到显示的差异。但是,Apple并没有迅速更新ncurses。 linux2.2终端描述是在原始问题的上下文中使用的描述。这是一个屏幕截图,显示了具有该终端描述的ncurses测试程序:

example of problem using Terminal.app

现在......苹果可能已经赶上Mohave,但目前还没有可靠的测试结果。使用High Sierra,Apple对 linux 的终端说明仍然使用较旧版本的图形字符,如此屏幕截图所示:

linux terminal description in High Sierra

现在......如果您使用的是MacPorts或brew,结果会有所不同:

  • 这些添加的终端数据库更新,
  • 新数据库中的一个功能是 linux 终端描述使用U8 extension,它告诉ncurses假设它应该在语言环境时使用UTF-8编码是UTF-8。如果你遇到这种情况,你就不会看到原来的问题。

答案 1 :(得分:0)

在终端中,依次转到“首选项”,“个人档案”,然后单击“高级”选项卡。在高级菜单中,选择文本编码的下拉菜单,然后选择西方(Mac OS Roman)。我确定其他编码都有您所缺少的字符-但这对我有用。