简体   繁体   English

urxvt 中的 ncurses 不打印重复字符

[英]ncurses in urxvt does not print repeating characters

Running an ncurses program in urxvt squeezes repeating characters in strings.urxvt 中运行ncurses程序挤压字符串中的重复字符。 For example I expect "--------" but I get "-" .例如,我期望"--------"但我得到"-"

I have written a short program that reproduces the problem.我写了一个小程序来重现这个问题。 The code is below.代码如下。

I have verified that the output is as correct when using xterm rather than urxvt .我已经验证在使用xterm而不是urxvt时输出是正确的。

This is the first time I am working with ncurses, however, the sample program is as simple as they come.这是我第一次使用 ncurses,但是,示例程序和它们一样简单。 Therefore, I don't think it is likely that the problem is with how I'm using ncurses.因此,我认为问题不在于我如何使用 ncurses。 This is also supported by the fact that xterm gives the expected results. xterm 给出了预期的结果这一事实也支持了这一点。

I am using urxvt on Arch Linux.我在 Arch Linux 上使用 urxvt。 I am providing related configuration below too.我也在下面提供相关配置。 I have vanilla xterm installed without any additional configuration.我在没有任何额外配置的情况下安装了 vanilla xterm。 Both had zsh running.两者都运行了 zsh。

Sample Program (C)示例程序 (C)

#include <curses.h>

int main(){
  initscr();
  printw("------\n");        // (1) 6 '-' chars          urxvt: "------"   xterm: "------"
  printw("-------\n");       // (2) 7 '-' chars          urxvt: "-"        xterm: "-------"
  printw("--------\n");      // (3) 8 '-' chars          urxvt: "-"        xterm: "--------"
  printw("0--------0\n");    // (4) 8 '-' between '0'    urxvt: "0-0"      xterm: "0--------0"
  printw("xxxxxxxx\n");      // (5) Replacing '-' with 'x' does not make a difference.
  printw("---- ----\n");     // (6) Two '-' sequences separated by ' ' display correctly.
  printw("12345678\n");      // (7) Strings with different characters display correctly.
  for(int i=0; i<8; i++) addch('-');    // (8) 8 '-' chars      urxvt: "-"   xterm: "--------" 
  addch('\n');
  for(char c='0'; c<'8'; c++) addch(c); // (9) Both display correctly
  addch('\n');
  refresh();
  getch();
  endwin();
  return 0;
}

xterm Output (Correct) xterm 输出(正确)

------
-------
--------
0--------0
xxxxxxxx
---- ----
12345678
--------
01234567

urxvt Output (Incorrect) urxvt 输出(不正确)

------
-
-
0-0
x
---- ----
12345678
-
01234567

Observations观察

  • Up to 6 repeating characters are displayed correctly.最多可正确显示 6 个重复字符。
  • 7 and more repeating characters are displayed as a single character. 7 个或更多重复字符显示为单个字符。
  • This problem does not occur if the characters are non-repeating, so the length of the string itself is not the problem.如果字符不重复,则不会出现此问题,因此字符串本身的长度不是问题。
  • The location of the repeating substring is not important.重复子串的位置并不重要。 In (7), the substring that got squeezed was sandwiched by '0' characters on each end.在(7)中,被压缩的子串在每一端被'0'字符夹在中间。
    • The problem is not due to a specific character.问题不是由特定字符引起的。 It happens with '-' as well as 'x' .它发生在'-'以及'x'
  • The problem was observed using both the printw and addch functions.使用printwaddch函数观察到该问题。 The associated manpages state that these functions move the cursor, so there should be no need to explicitly move the cursor.相关的联机帮助页指出这些函数会移动光标,因此不需要显式移动光标。 This is obviously the case, as otherwise the problem would not be limited to repeating characters, and would also happen with xterm.显然是这样,否则问题将不仅限于重复字符,而且 xterm 也会发生。

urxvt Configuration urxvt 配置

  • rxvt-unicode v9.22 rxvt-unicode v9.22
  • $TERM is xterm-256color $TERMxterm-256color

urxvt is not xterm, so $TERM should be rxvt-unicode and not xterm-256color . urxvt 不是 xterm,所以$TERM应该是rxvt-unicode而不是xterm-256color

I didn't figure this out right until the very end of typing my question, when I was adding the urxvt configuration.直到我输入问题的最后,当我添加 urxvt 配置时,我才弄清楚这一点。 I suppose thinking about what information might be relevant to put into a SO question is can lead to solving your own problem.我想考虑将哪些信息放入 SO 问题可能会导致解决您自己的问题。 Rather than deleting everything, I thought I might as well post nonetheless and perhaps it will be useful to someone else out there.与其删除所有内容,我还是想我还是发布一下,也许它对其他人有用。

The thing is, I added that env setting a long, long time ago when I was experimenting with Arch Linux and urxvt for the first time.问题是,我在很久很久以前第一次尝试 Arch Linux 和 urxvt 时添加了 env 设置。 I must admit, I did not really spend too much time thinking about it.我必须承认,我并没有花太多时间考虑它。 I recall all I cared about at the time was having unicode characters, fonts and colors displayed properly (in addition to a pretty looking color scheme).我记得当时我所关心的只是正确显示 unicode 字符、字体和颜色(除了漂亮的配色方案)。 Setting $TERM to xterm-256color seemed to work at the time, and in all this time using the system, it continued seeming to work, until today.$TERM设置$TERM xterm-256color在当时似乎有效,并且在使用该系统的所有时间里,它似乎继续有效,直到今天。 There were glitches here and there, of course, and perhaps they were the result of this.当然,这里和那里都有小故障,也许它们就是这样的结果。 Then again, perhaps they were due to something else.再说一次,也许他们是由于其他原因。 I have to say I am rather amused at how silly and simple the problem turned out to be.我不得不说我对这个问题竟然如此愚蠢和简单感到很有趣。

It is also interesting to see the strange behavior this error led to.看到这个错误导致的奇怪行为也很有趣。 I'm still curious to know why exactly my mistake leads to the behavior I document in the question.我仍然很想知道为什么我的错误会导致我在问题中记录的行为。 I might return to this just for kicks when I have some time.当我有时间的时候,我可能会回到这个只是为了踢球。

EDIT编辑

This exact issue is mentioned in ncurses' FAQ , as pointed out by Thomas Dickey .正如Thomas Dickey所指出的,ncurses 的常见问题解答中提到了这个确切的问题。

..., in mid-2017, an update to the xterm terminal description added the ECMA-48 REP (repeat character) control. ...,在 2017 年年中,xterm 终端描述的更新添加了 ECMA-48 REP(重复字符)控件。 It was part of xterm since January 1997, but a terminal description using the feature was part of xterm only (not ncurses).自 1997 年 1 月以来,它是 xterm 的一部分,但使用该功能的终端描述只是 xterm 的一部分(不是 ncurses)。

Terminal emulators that use TERM=xterm but do not support this xterm feature exhibited bugs once this feature was introduced to ncurses.一旦将此功能引入 ncurses,使用 TERM=xterm 但不支持此 xterm 功能的终端仿真器就会出现错误。 rxvt was unaffected since it does not use TERM=xterm, or rather, as it should not use TERM=xterm, as I had been doing. rxvt 不受影响,因为它不使用 TERM=xterm,或者更确切地说,它不应该使用 TERM=xterm,就像我一直在做的那样。

REP is used to indicate that the preceding character in the data stream, if it is a graphic character (represented by one or more bit combinations) including SPACE, is to be repeated n times, where n equals the value of Pn. REP用于表示数据流中的前一个字符,如果是包含SPACE的图形字符(由一个或多个位组合表示),则重复n次,其中n等于Pn的值。 If the character preceding REP is a control function or part of a control function, the effect of REP is not defined by this Standard.如果 REP 前面的字符是控制功能或控制功能的一部分,则 REP 的效果不在本标准中定义。 REP - ECMA-048 REP - ECMA-048

I should also mention that the ncurses FAQ includes an excellent discussion concerning why people tend to use TERM=xterm, and why they should not, straight from the horse's mouth!我还应该提到,ncurses 常见问题解答包括一个关于为什么人们倾向于使用 TERM=xterm 以及为什么不应该直接从马嘴里说出来的精彩讨论!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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