简体   繁体   中英

ncurses A_ALTCHARSET characters not displaying on OSX

I am using ncurses in a c++ program and want to be able to use A_ALTCHARSET characters. On my linux computer it was working fine but then when I tried it on my Mac several characters showed up as '?'. As a test I ran the second program from this website on both of my computers. On my linux computer it showed all the characters correctly and showed the same thing as the picture on the website but on my mac I got:

                                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 = ? │ 

Why isn't this working and is there a away to fix it?

That looks as if you did something like setting TERM to linux . The Linux console provides a non-VT100 method for drawing line-graphics (essentially using codes from 160-255). OSX Terminal implements a VT100-style line-graphics, which requires switching character-sets. As shown in the screenshot, linux is not one of the settings that you might make with Terminal's preferences. However it's not unusual for people to set the variable in their .bashrc , etc.:

显示Apple假定的可用terminfo条目

The terminal description (selected by the TERM environment variable) is different in this area. The recommended TERM for OSX Terminal is one of the nsterm flavors in ncurses. Comparing:

$ 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'.

The smacs and rmacs strings in the VT100-style capabilities are called shift-in and shift-out (for the normal and graphics). As you may see, they're not like the Linux capabilities.

Further reading:

The feature to look for is the value of TERM which your program is using in the shell. OSX Terminal only has one possible behavior (none match "linux"). The program does have a Preferences dialog which sets TERM , although your shell may explictly set it to some other value. For instance, the terminal database notes that

# * 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

The above was written in February 2016. Development of ncurses and Linux is ongoing. In May 2016 this change was made to ncurses' terminal database:

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

That made the standard linux terminal description look more like nsterm in this area. If you were running infocmp on an up-to-date system, you would not see the difference shown. Apple, however, does not update ncurses that rapidly. The linux2.2 terminal description is what one would be using in the context of the original question. Here's a screenshot showing the ncurses test-program with that terminal description:

使用Terminal.app的问题的示例

Now... Apple may have caught up with Mohave, but there have been no credible test-results from that yet. With High Sierra, Apple's terminal description for linux still uses the older version of graphics characters as shown in this screenshot:

High Sierra中的linux终端说明

Now... if you were using MacPorts or brew, the result would be different:

  • the terminal database added by those is newer, and
  • one of the features in the newer database is that the linux terminal description uses the U8 extension , which tells ncurses to assume it should use UTF-8 when the locale encoding is UTF-8. If you had that situation, you would not see the original problem.

In terminal, go to "Preferences", then "Profiles", and click on the "Advanced" tab. In advanced, select the dropdown menu of Text Encodings and select Western (Mac OS Roman). I'm sure other encodings have the characters you're missing - but that one worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM