xterm不显示unicode


8

我从来没有能够让我的终端显示unicode符号。例如,在我拥有现在的操作系统之前,我将ctrl + a映射到vim中的希腊mu,并且它可以在其他计算机上运行,​​但不能在当前的xterm上运行。这是我的相关部分.vimrc

set encoding=utf-8
"map control-a to mu
imap <C-a> <C-k>m*

另外,我需要在python中输出sympy方程,这在其他计算机上有效,但在我当前的xterm上不可用。代替这个:

$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy
>>> x = sympy.symbols('x')
>>> sympy.init_printing()
>>> (sympy.sqrt(x**3/(x+1)), 1)
⎛     _______   ⎞
⎜    ╱    3     ⎟
⎜   ╱    x      ⎟
⎜  ╱   ───── , 1⎟
⎝╲╱    x + 1    ⎠

我得到这个:

>>> (sympy.sqrt(x**3/(x+1)), 1)
n      -------   n
n     n    3     n
n    n    x      n
n   n   ───── , 1n
nnnn    x + 1    n

实际上,它似乎仅在n无法显示unicode字符时才使用该字符。

我正在从~/.xinitrc文件运行xterm,并在中为终端设置了一些字体和颜色~/.Xresources。这是我能想到的所有相关信息:

$ uname -a
Linux mypcname 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux
$ xterm -version
XTerm(278)
$ cat ~/.xinitrc 
#!/bin/bash

#update the xterm colors, font size, etc
[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources

# run the window manager in the background first
metacity &

# get the window manager process id
wm_pid=$!

# wait a little while for the window manager to load (extend this if the xterm is not being properly maximised)
sleep 2

# run the xterm in fullscreen
#xterm +u8 -js -fullscreen &
xterm -en en_AU.UTF-8 -js -fullscreen &

# do not let the window manager become a zombie
wait $wm_pid

# this would run xterm first, then the window manager. doesn't maximise properly the first time startx is run
#xterm -fullscreen &
#exec mutter

$ cat ~/.Xresources 
! see man xterm under the resources heading for explanations
! run `xrdb -merge ~/.Xresources` after altering this file
! run `xrdb -query -all` to see the current settings

xterm.vt100.faceName: Terminus
xterm.vt100.faceSize: 14
! do not display bold fonts in bold
xterm.vt100.AllowBoldFonts: false
! display bold fonts in a different color to make them stand out
xterm.vt100.colorBDMode: true
! use green as the bold color (same as in ~/.bashrc)
xterm.vt100.colorBD: #98E34D

! cols x lines ... update with values from $(echo $COLUMNS) and $(echo $LINES)
xterm.vt100.geometry: 126x52

! dark green foreground (same as in ~/.bashrc)
*foreground: #4E9A06
! black background
*background: #000000

! scroll quickly
xterm*fastScroll: true

! enable utf-8 encoding
xterm*locale: true
xterm*utf8: 1

! flash the current line instead of making the bell sound
*visualBell: true
*visualBellLine: true

! black
*color0: #2E3436
! darkred
*color1: #CC0000
! dark green
*color2: #4E9A06
! brown
*color3: #C4A000
! darkblue
*color4: #3465A4
! darkmagenta
*color5: #75507B
! darkcyan
*color6: #06989A
! lightgrey
*color7: #D3D7CF
! darkgrey
*color8: #555753
! red
*color9: #EF2929
! green
*colorA: #8AE234
! yellow
*colorB: #FCE94F
! blue
*colorC: #729FCF
! magenta
*colorD: #AD7FA8
! cyan
*colorE: #34E2E2
! white
*colorF: #EEEEEC

$ tail -10 .bashrc
PATH=/usr/local/bin:/usr/bin:/bin:/sbin

export LC_ALL=en_AU.UTF-8
export LANG=en_AU.UTF-8
export LANGUAGE=en_AU.UTF-8

# final logon actions:

# go straight to x on login. only do this for tty1 so that we can still use the other tty consoles without starting x. also only do this when there is not already a display, otherwise the xterm will try and do this after x starts aswell
[[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]] && startx

$ locale
LANG=en_AU.UTF-8
LANGUAGE=en_AU.UTF-8
LC_CTYPE="en_AU.UTF-8"
LC_NUMERIC="en_AU.UTF-8"
LC_TIME="en_AU.UTF-8"
LC_COLLATE="en_AU.UTF-8"
LC_MONETARY="en_AU.UTF-8"
LC_MESSAGES="en_AU.UTF-8"
LC_PAPER="en_AU.UTF-8"
LC_NAME="en_AU.UTF-8"
LC_ADDRESS="en_AU.UTF-8"
LC_TELEPHONE="en_AU.UTF-8"
LC_MEASUREMENT="en_AU.UTF-8"
LC_IDENTIFICATION="en_AU.UTF-8"
LC_ALL=en_AU.UTF-8

$ printenv XTERM_LOCALE
en_AU.UTF-8

$ xrdb -query -all
*background:    #000000
*color0:    #2E3436
*color1:    #CC0000
*color2:    #4E9A06
*color3:    #C4A000
*color4:    #3465A4
*color5:    #75507B
*color6:    #06989A
*color7:    #D3D7CF
*color8:    #555753
*color9:    #EF2929
*colorA:    #8AE234
*colorB:    #FCE94F
*colorC:    #729FCF
*colorD:    #AD7FA8
*colorE:    #34E2E2
*colorF:    #EEEEEC
*foreground:    #4E9A06
*visualBell:    true
*visualBellLine:    true
xterm*fastScroll:   true
xterm*locale:   true
xterm*utf8: 1
xterm.vt100.AllowBoldFonts: false
xterm.vt100.colorBD:    #98E34D
xterm.vt100.colorBDMode:    true
xterm.vt100.faceName:   Terminus
xterm.vt100.faceSize:   14
xterm.vt100.geometry:   126x52

如何让utf-8在vim中显示希腊符号并在其中显示方程式sympy


要求额外信息

$ echo $TERM
xterm
$ appres XTerm
*form.Thickness:    0
*tekMenu*tekreset*Label:    RESET
*tekMenu*tektext2*Label:    #2 Size Characters
*tekMenu*tekhide*Label: Hide Tek Window
*tekMenu*tekcopy*Label: COPY
*tekMenu*tektext3*Label:    #3 Size Characters
*tekMenu*vtshow*Label:  Show VT Window
*tekMenu*tektextsmall*Label:    Small Characters
*tekMenu*vtmode*Label:  Switch to VT Mode
*tekMenu*tektextlarge*Label:    Large Characters
*tekMenu*tekpage*Label: PAGE
*tekMenu.Label: Tek Options
*mainMenu*redraw*Label: Redraw Window
*mainMenu*sunKeyboard*Label:    VT220 Keyboard
*mainMenu*terminate*Label:  Send TERM Signal
*mainMenu*backarrow key*Label:  Backarrow Key (BS/DEL)
*mainMenu*logging*Label:    Log to File
*mainMenu*hpFunctionKeys*Label: HP Function-Keys
*mainMenu*kill*Label:   Send KILL Signal
*mainMenu*num-lock*Label:   Alt/NumLock Modifiers
*mainMenu*print-immediate*Label:    Print-All Immediately
*mainMenu*scoFunctionKeys*Label:    SCO Function-Keys
*mainMenu*quit*Label:   Quit
*mainMenu*alt-esc*Label:    Alt Sends Escape
*mainMenu*print-on-error*Label: Print-All on Error
*mainMenu*tcapFunctionKeys*Label:   Termcap Function-Keys
*mainMenu*meta-esc*Label:   Meta Sends Escape
*mainMenu*toolbar*Label:    Toolbar
*mainMenu*print*Label:  Print Window
*mainMenu*suspend*Label:    Send STOP Signal
*mainMenu*delete-is-del*Label:  Delete is DEL
*mainMenu*print-redir*Label:    Redirect to Printer
*mainMenu*fullscreen*Label: Full Screen
*mainMenu*continue*Label:   Send CONT Signal
*mainMenu*oldFunctionKeys*Label:    Old Function-Keys
*mainMenu*securekbd*Label:  Secure Keyboard
*mainMenu*interrupt*Label:  Send INT Signal
*mainMenu*8-bit control*Label:  8-Bit Controls
*mainMenu*allowsends*Label: Allow SendEvents
*mainMenu*sunFunctionKeys*Label:    Sun Function-Keys
*mainMenu*hangup*Label: Send HUP Signal
*mainMenu.Label:    Main Options
*VT100.utf8Fonts.font4: -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso10646-1
*VT100.utf8Fonts.font2: -misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1
*VT100.utf8Fonts.font6: -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1
*VT100.utf8Fonts.font5: -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
*VT100.utf8Fonts.font3: -misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1
*VT100.utf8Fonts.font:  -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1
*VT100.font4:   7x13
*VT100.font2:   5x7
*VT100.font6:   10x20
*VT100.font5:   9x15
*VT100.font3:   6x10
*VT100.font1:   nil2
*vtMenu*selectToClipboard*Label:    Select to Clipboard
*vtMenu*reversewrap*Label:  Enable Reverse Wraparound
*vtMenu*softreset*Label:    Do Soft Reset
*vtMenu*cursesemul*Label:   Enable Curses Emulation
*vtMenu*autolinefeed*Label: Enable Auto Linefeed
*vtMenu*hardreset*Label:    Do Full Reset
*vtMenu*visualbell*Label:   Enable Visual Bell
*vtMenu*appcursor*Label:    Enable Application Cursor Keys
*vtMenu*clearsavedlines*Label:  Reset and Clear Saved Lines
*vtMenu*bellIsUrgent*Label: Enable Bell Urgency
*vtMenu*appkeypad*Label:    Enable Application Keypad
*vtMenu*tekshow*Label:  Show Tek Window
*vtMenu*poponbell*Label:    Enable Pop on Bell
*vtMenu*scrollbar*Label:    Enable Scrollbar
*vtMenu*scrollkey*Label:    Scroll to Bottom on Key Press
*vtMenu*tekmode*Label:  Switch to Tek Mode
*vtMenu*scrollttyoutput*Label:  Scroll to Bottom on Tty Output
*vtMenu*jumpscroll*Label:   Enable Jump Scroll
*vtMenu*cursorblink*Label:  Enable Blinking Cursor
*vtMenu*vthide*Label:   Hide VT Window
*vtMenu*allow132*Label: Allow 80/132 Column Switching
*vtMenu*reversevideo*Label: Enable Reverse Video
*vtMenu*titeInhibit*Label:  Enable Alternate Screen Switching
*vtMenu*altscreen*Label:    Show Alternate Screen
*vtMenu*keepSelection*Label:    Keep Selection
*vtMenu*autowrap*Label: Enable Auto Wraparound
*vtMenu*activeicon*Label:   Enable Active Icon
*vtMenu.Label:  VT Options
*SimpleMenu*menuLabel.font: -adobe-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-*
*SimpleMenu*menuLabel.vertSpace:    100
*SimpleMenu*Sme.height: 16
*SimpleMenu*BackingStore:   NotUseful
*SimpleMenu*HorizontalMargins:  16
*SimpleMenu*Cursor: left_ptr
*SimpleMenu*borderWidth:    2
*menubar.borderWidth:   0
*tek4014*fontLarge: 9x15
*tek4014*font2: 8x13
*tek4014*font3: 6x13
*tek4014*fontSmall: 6x10
*MenuButton*borderWidth:    0
*fontMenu*render-font*Label:    TrueType Fonts
*fontMenu*fontdefault*Label:    Default
*fontMenu*font6*Label:  Huge
*fontMenu*allow-window-ops*Label:   Allow Window Ops
*fontMenu*utf8-mode*Label:  UTF-8 Encoding
*fontMenu*font1*Label:  Unreadable
*fontMenu*fontescape*Label: Escape Sequence
*fontMenu*utf8-fonts*Label: UTF-8 Fonts
*fontMenu*fontsel*Label:    Selection
*fontMenu*allow-bold-fonts*Label:   Bold Fonts
*fontMenu*utf8-title*Label: UTF-8 Titles
*fontMenu*font-linedrawing*Label:   Line-Drawing Characters
*fontMenu*font2*Label:  Tiny
*fontMenu*allow-color-ops*Label:    Allow Color Ops
*fontMenu*font-doublesize*Label:    Doublesized Characters
*fontMenu*font3*Label:  Small
*fontMenu*allow-font-ops*Label: Allow Font Ops
*fontMenu*font-loadable*Label:  VT220 Soft Fonts
*fontMenu*font4*Label:  Medium
*fontMenu*allow-tcap-ops*Label: Allow Termcap Ops
*fontMenu*font-packed*Label:    Packed Font
*fontMenu*font5*Label:  Large
*fontMenu*allow-title-ops*Label:    Allow Title Ops
*fontMenu.Label:    VT Fonts
*colorD:    #AD7FA8
*color5:    #75507B
*backarrowKeyIsErase:   true
*colorE:    #34E2E2
*color6:    #06989A
*ptyInitialErase:   true
*colorF:    #EEEEEC
*background:    #000000
*color7:    #D3D7CF
*saveLines: 1024
*color8:    #555753
*color0:    #2E3436
*foreground:    #4E9A06
*IconFont:  nil2
*color9:    #EF2929
*color1:    #CC0000
*visualBell:    true
*colorA:    #8AE234
*color2:    #4E9A06
*visualBellLine:    true
*colorB:    #FCE94F
*color3:    #C4A000
*colorC:    #729FCF
*color4:    #3465A4
$ xterm -u8 -fa "DejaVu Sans Mono"
# the following is typed in the resulting terminal:
$ echo -e "\xE2\x98\xA0"
n
# however when i copy the result from `echo -e "\xE2\x98\xA0"`
# into my browser, i get this: ☠ (a skull) but it does not show
# up as a skull in my xterm

$ lsof -p $PPID | grep fonts
xterm   5990 me  mem    REG              254,1     4971 13501810 /usr/share/fonts/X11/misc/ter-u18b_iso-8859-1.pcf.gz
xterm   5990 me  mem    REG              254,1     4897 13505403 /usr/share/fonts/X11/misc/ter-u18n_iso-8859-1.pcf.gz

我也跑了,$ fc-list但输出太大,无法粘贴到此问题中。所以我把它放在这里

它在我的浏览器中显示的内容:

/usr/share/fonts/truetype/freefont/FreeSansBold.ttf: FreeSans:style=Bold,получерен,negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,gros,Полужирный,Fet,Kalın,huruf tebal,жирний,Krepko,treknraksts,pusjuodis,đậm,Lodia,धृष्ट

我在终端中看到的内容:

/usr/share/fonts/truetype/freefont/FreeSansBold.ttf: FreeSans:style=Bold,nnnnnnnnn,negreta,tunné,fed,Fett,nnnnnn,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,gros,nnnnnnnnnn,Fet,Kalın,huruf tebal,nnnnnn,Krepko,treknraksts,pusjuodis,nậm,Lodia,nnn

有趣的是,我的终端上确实出现了一些“特殊”字符,但是大多数字符被代替n。您可以在上一个输出中看到получерен无法显示任何内容,但是可以显示的最后一个字符tučné(而中间č则不能显示-被代替n


根据@apaul的评论,看来xterm加载的字体不正确。尝试设置一个虚拟类,以免加载xterm资源:

$ xterm -class Foo -name foo -u8 -fa "DejaVu Sans Mono:style=Book"
$ # the following commands are all executed in the resulting terminal:
$ echo -e "\xE2\x98\xA0"
☠
$ # the above skull actually shows up now. and so does the unicode
$ # output from sympy and also vi can display greek symbols now :)

剩下的一切就是弄清楚为什么xterm无法使用来设置字体~/.Xresoureces,并使其正常工作。似乎必须覆盖字体设置?

实际上我只是想尝试使用Terminus字体尝试上述命令,看来这是问题所在:

$ xterm -class Foo -name foo -u8 -fa "Terminus"
$ # the following commands are all executed in the resulting terminal:
$ echo -e "\xE2\x98\xA0"
n

也许总站未正确安装?或正被映射到其他东西。我怎么能找到答案?


2
xterm不支持​​完整的UTF-8(AFAIK),请尝试运行uxterm,但我建议您尝试使用其他终端,例如urxvt,白蚁或st
zer0rest 2015年

rxvt-unicode作品:)
mulllhausen'Aug

1
@mulllhausen我确认它应该可以工作。我使用xterm已有多年,并且可以显示很多内容,具体取决于字体。总站能够显示您的示例。我正在使用-fa "DejaVu Sans Mono:size=11:antialias=true"但是,我不理解您的-js-fullscreen选项。我的xterm版本不了解它们。我的xterm -version输出X.Org 6.8.99.903(253)
apaul 2015年

3
@mulllhausen好吧,由于复制粘贴有效,这意味着xterm可以处理unicode。可能是字体问题。您确定xterm正在使用“ DejaVu Sans Mono”吗?您可以检查它是否在xterm中运行,lsof -p $PPID | grep fonts并使用来检查xterm 可以看到的字体列表fc-list
apaul 2015年

1
@mulllhausen Thx。如您所见,由于某些原因,xterm不会加载正确的字体。它加载了一个iso-8859-1(包含“é”,这就是为什么您可以看到它)。老实说,我不知道为什么。你会跑步xterm -class Foo -name foo -u8 -fa "DejaVu Sans Mono:style=Book"吗?(在这里我们设置了一个虚拟类和名称,这样它就不会加载XTerm*资源。)
apaul 2015年

Answers:


7

写在2016年,谈论xterm补丁#278(2012年发布):

xterm使用一种字体,而不是其他几种终端所支持的字体。伪图形字符(从xterm粘贴):

⎛     ⎽⎽⎽⎽⎽⎽⎽   ⎞
⎜    ╱    3     ⎟
⎜   ╱    x      ⎟
⎜  ╱   ───── , 1⎟
⎝╲╱    x + 1    ⎠

在此处指定的TypeType字体提供:

xterm.vt100.faceName: Terminus
xterm.vt100.faceSize: 14

给定字体将提供其他字体中的那些字符的其他终端。

使xterm工作的方法是

  • 指定一种可以覆盖所有所需字符的字体,并且
  • 告诉它使用UTF-8编码。

后者是通过locale资源的默认设置为大多数用户解决的:xterm(通常)将使用UTF-8编码。但是默认行为是VT100兼容的,因此使用ISO-8859-1兼容的字体。

  • Terminus使用的字形更多,但远远不足以覆盖Unicode中的所有伪图形。
  • 显示为的n是U + 239B,U + 239C,U + 239D,U + 239E,U + 23A0。
  • Debian 7(和Debian测试)中的Terminus版本少于256个字形,并且恰好n按照问题中所述显示。

发生这种情况的原因是(尽管xterm知道缺少字形),但它使用字体打印了字符串,并假设缺少的条目(像大多数其他字体一样)将显示为blanks。在这种情况下,freetype库似乎正在 Unicode值的低位字节映射到Terminus支持的范围内。这恰好落在字体显示为的范围内n(“无此字符”):

在此处输入图片说明

快速的解决方法是使用uxterm脚本,该脚本选择其他字体并确保使用UTF-8编码。

进一步阅读:

Terminus字体是一种干净的,固定宽度的位图字体,设计用于长时间(每天8个或更长时间)与计算机一起使用。版本4.40包含1241个字符,涵盖约120种语言集,并支持ISO8859-1 / 2/5/7/9/13/15/16,Paratype-PT154 / PT254,KOI8-R / U / E / F,世界语,许多IBM,Windows和Macintosh代码页,以及IBM VGA,vt100和xterm伪字符。

以上是关于xterm 278号补丁程序的信息,该补丁程序在2016年已有 4年历史。xterm的 开发正在进行中,从 338号补丁程序(2018年末)开始,就支持TrueType字体集。这是使用xterm补丁#342中 OP的资源设置的屏幕截图(#343可能很快就会发布):

xterm#342的屏幕截图

使用该-report-fonts选项,我看到它加载了这些字体文件(与正常情况一样,将粗体/斜体处理为“相同” ,并对特殊字符使用第二种字体):

    file=/usr/share/fonts/X11/misc/ter-u18n\_iso-8859-1.pcf.gz              
    file=/usr/share/fonts/X11/misc/ter-u18b\_iso-8859-1.pcf.gz              
    file=/usr/share/fonts/X11/misc/ter-u18n\_iso-8859-1.pcf.gz              
    file=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf

实际的字体数量取决于您要执行的操作。在测试Unicode值的现有范围时,它可能使用几十种字体。


您是否有计划在xterm中为缺少字体的其他字体添加对后备字体的支持?
斯特凡Chazelas

我缺一会儿:-(字体集会不错,但是要花几个月的时间...
Thomas Dickey

几个月似乎仍然是一个不错的估计(我的估计数字约为2/3)。
Thomas Dickey

5

来自评论的解决方案:

  • uxterm
  • Ctrl右键单击(上下文菜单)和UTF-8编码。
  • xterm -u8
  • X资源:使用字体规范,将字符集和econding字段设置为-iso10646-1

例如,对于xterm(X-cl​​ass Xterm)和Terminus字体,您可以添加到〜/ .Xresources

XTerm*font: -*-terminus-medium-r-normal--18-*-*-*-*-*-iso10646-1

要查找系统上安装的字体及其字体规格,请参阅/usr/share/fonts/*/*.dir文件。编辑后~/.Xresources,用加载它们xrdb -merge ~/.Xresources


2

不幸的是,我也没有能够在中正确配置unicode支持xterm。作为解决方法,我最终安装了EL发行版上的rpmforgerxvt提供的。该程序还有unicode-256color版本,对我来说非常有用。描述如下:

Name        : rxvt
Arch        : x86_64
Epoch       : 18
Version     : 2.7.10
Release     : 2.el7.rf
Size        : 326 k
Repo        : rpmforge
Summary     : Color VT102 terminal emulator for the X Window System
URL         : http://www.rxvt.org/
License     : GPL
Description : Rxvt is a color VT102 terminal emulator for the X Window System. Rxvt
            : is intended to be an xterm replacement for users who don't need the
            : more esoteric features of xterm, like Tektronix 4014 emulation,
            : session logging and toolkit style configurability. Since it does not
            : support those features, rxvt uses much less swap space than xterm
            : uses. This is a significant advantage on a machine which is serving a
            : large number of X sessions.

ArchWiki具有关于配置和用例的有用信息。


1
我现在用rxvt-unicode
mulllhausen

errgh ...所以,我的回答是一个可行的解决方案/解决方法?
ILMostro_7

1
大概吧。我仍然想知道是否有办法修复xterm
mulllhausen

0

使用以下TrueType字体怎么样?我无法-fn *-*-...使用xterm使用标准选项,但这非常有效。

xterm -fa 'Inconsolata' -fs 12

Inconsolata字体可以在这里下载

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.