urxvt中的ncurses不打印重复字符 [英] ncurses in urxvt does not print repeating characters

查看:82
本文介绍了urxvt中的ncurses不打印重复字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

urxvt 压缩中运行 ncurses 程序,在字符串中重复字符.例如,我期望"--------",但得到"-".

Running an ncurses program in urxvt squeezes repeating characters in strings. For example I expect "--------" but I get "-".

我写了一个简短的程序来重现该问题.代码如下.

I have written a short program that reproduces the problem. The code is below.

我已验证使用 xterm 而不是 urxvt 时输出正确.

I have verified that the output is as correct when using xterm rather than urxvt.

这是我第一次使用ncurses,但是示例程序非常简单.因此,我认为问题不太可能出在我使用ncurses的方式上. xterm给出了预期的结果也支持了这一点.

This is the first time I am working with ncurses, however, the sample program is as simple as they come. Therefore, I don't think it is likely that the problem is with how I'm using ncurses. This is also supported by the fact that xterm gives the expected results.

我在Arch Linux上使用urxvt.我也在下面提供相关的配置.我安装了香草xterm,没有任何其他配置.两者都运行zsh.

I am using urxvt on Arch Linux. I am providing related configuration below too. I have vanilla xterm installed without any additional configuration. Both had zsh running.

#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输出(正确)

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

urxvt输出(不正确)

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

观察

  • 最多可以正确显示6个重复字符.
  • 7个及更多重复字符显示为单个字符.
  • 如果字符不重复,则不会发生此问题,因此字符串本身的长度不是问题.
  • 重复的子字符串的位置并不重要.在(7)中,被压缩的子字符串的每一端都夹有'0'个字符.
    • 问题不是由于特定字符引起的. '-''x'都会发生这种情况.
    • Observations

      • Up to 6 repeating characters are displayed correctly.
      • 7 and more repeating characters are displayed as a single character.
      • 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.
        • The problem is not due to a specific character. It happens with '-' as well as 'x'.
          • rxvt-unicode v9.22
          • $TERMxterm-256color

          推荐答案

          urxvt不是xterm,所以$TERM应该是rxvt-unicode而不是xterm-256color.

          urxvt is not xterm, so $TERM should be rxvt-unicode and not xterm-256color.

          在添加urxvt配置时,直到输入问题的最后,我才弄清楚这一点.我想考虑与SO问题相关的信息可能会导致解决您自己的问题.除了删除所有内容外,我认为我还是应该发布,这可能对那里的其他人很有用.

          I didn't figure this out right until the very end of typing my question, when I was adding the urxvt configuration. I suppose thinking about what information might be relevant to put into a SO question is can lead to solving your own problem. Rather than deleting everything, I thought I might as well post nonetheless and perhaps it will be useful to someone else out there.

          问题是,很久以前,当我第一次尝试使用Arch Linux和urxvt时,我添加了env设置.我必须承认,我并没有花太多时间考虑它.我记得当时我只关心正确显示unicode字符,字体和颜色(除了漂亮的配色方案).将$TERM设置为xterm-256color似乎在当时是可行的,并且在使用系统的所有时间中,它一直在起作用,直到今天.当然,到处都是小故障,也许是这造成的.再说一遍,也许他们是由于其他原因.我不得不说这个问题多么愚蠢和简单,我感到很有趣.

          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. 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). 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. 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.

          编辑

          ncurses的常见问题解答中提到了此确切问题, 托马斯·迪基指出.

          This exact issue is mentioned in ncurses' FAQ, as pointed out by Thomas Dickey.

          ...,在2017年中,对xterm终端说明进行了更新,添加了ECMA-48 REP(重复字符)控件.自1997年1月以来,它是xterm的一部分,但是使用该功能的终端说明仅是xterm的一部分(不是ncurses).

          ..., in mid-2017, an update to the xterm terminal description added the ECMA-48 REP (repeat character) control. It was part of xterm since January 1997, but a terminal description using the feature was part of xterm only (not ncurses).

          使用TERM = xterm但不支持此xterm功能的终端仿真器在将ncurses引入该功能后会出现错误. rxvt不受影响,因为它不使用TERM = xterm,或者像我一直在使用的那样,不应该使用TERM = xterm.

          Terminal emulators that use TERM=xterm but do not support this xterm feature exhibited bugs once this feature was introduced to ncurses. rxvt was unaffected since it does not use TERM=xterm, or rather, as it should not use TERM=xterm, as I had been doing.

          REP用于指示数据流中的前一个字符(如果是包含SPACE的图形字符(由一个或多个位组合表示))要重复n次,其中n等于Pn的值.如果REP前面的字符是控件功能或控件的一部分 功能,REP的作用未在本标准中定义. REP-ECMA-048

          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. 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 - ECMA-048

          我还应该提到,ncurses常见问题包括有关人们为何倾向于使用TERM = xterm以及为什么不应该直接从马口中直接进行讨论的精彩讨论!

          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!

          这篇关于urxvt中的ncurses不打印重复字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆