Cygwin BASH和ANSI控制序列

时间:2022-12-05 19:34:10

Several things here:

这里有几件事:

  1. Can anyone point me at C code to decode ANSI console escape sequences?
  2. 任何人都可以指着我在C代码解码ANSI控制台转义序列?

  3. Is there a way to get Cygwin BASH to emulate a dumb old TTY?
  4. 有没有办法让Cygwin BASH模仿一个愚蠢的旧TTY?

Maybe this should be 2 questions.

也许这应该是2个问题。

Thanks.

2 个解决方案

#1


It's a somewhat indirect answer, but the GNU ncurses library handles terminals of all sorts. One way of finding out which control sequences are applicable to ANSI terminals would be to decompile an ANSI terminal description:

这是一个有点间接的答案,但GNU ncurses库处理各种终端。找出哪些控制序列适用于ANSI终端的一种方法是反编译ANSI终端描述:

infocmp ansi

This would give you the set of terminfo attributes that are used by curses programs to achieve effects on an ANSI terminal. Of course, you then have to know what those hieroglyphs mean.

这将为您提供一组terminfo属性,curses程序使用这些属性来实现对ANSI终端的影响。当然,你必须知道这些象形文字的意思。

On Cygwin, I got:

在Cygwin,我得到了:

$ infocmp ansi
#       Reconstructed via infocmp from file: /usr/share/terminfo/61/ansi
ansi|ansi/pc-term compatible with color,
    am, mc5i, mir, msgr,
    colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64,
    acsc=+\020\,\021\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376,
    bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J,
    cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B,
    cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
    cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P,
    dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
    el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, ht=\E[I, hts=\EH,
    ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J,
    indn=\E[%p1%dS, invis=\E[8m, kbs=^H, kcbt=\E[Z, kcub1=\E[D,
    kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L,
    mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, op=\E[39;49m,
    rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, rin=\E[%p1%dT,
    rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m,
    s0ds=\E(B, s1ds=\E)B, s2ds=\E*B, s3ds=\E+B,
    setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
    sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m,
    sgr0=\E[0;10m, smacs=\E[11m, smpch=\E[11m, smso=\E[7m,
    smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
    u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,

$

The '\E' notation refers to the ESC character.

'\ E'符号表示ESC字符。

Failing that, you could look up the standard itself.

如果做不到这一点,你可以查看标准本身。

#2


Tweaking the TERM environment variable might make applications based on terminfo/termcap avoid using advanced escape sequences. (export TERM=dumb) I am not sure that's what you want, though.

调整TERM环境变量可能会使基于terminfo / termcap的应用程序避免使用高级转义序列。 (导出TERM =哑)但我不确定这是你想要的。

#1


It's a somewhat indirect answer, but the GNU ncurses library handles terminals of all sorts. One way of finding out which control sequences are applicable to ANSI terminals would be to decompile an ANSI terminal description:

这是一个有点间接的答案,但GNU ncurses库处理各种终端。找出哪些控制序列适用于ANSI终端的一种方法是反编译ANSI终端描述:

infocmp ansi

This would give you the set of terminfo attributes that are used by curses programs to achieve effects on an ANSI terminal. Of course, you then have to know what those hieroglyphs mean.

这将为您提供一组terminfo属性,curses程序使用这些属性来实现对ANSI终端的影响。当然,你必须知道这些象形文字的意思。

On Cygwin, I got:

在Cygwin,我得到了:

$ infocmp ansi
#       Reconstructed via infocmp from file: /usr/share/terminfo/61/ansi
ansi|ansi/pc-term compatible with color,
    am, mc5i, mir, msgr,
    colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64,
    acsc=+\020\,\021\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376,
    bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J,
    cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B,
    cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
    cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P,
    dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
    el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, ht=\E[I, hts=\EH,
    ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J,
    indn=\E[%p1%dS, invis=\E[8m, kbs=^H, kcbt=\E[Z, kcub1=\E[D,
    kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L,
    mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, op=\E[39;49m,
    rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, rin=\E[%p1%dT,
    rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m,
    s0ds=\E(B, s1ds=\E)B, s2ds=\E*B, s3ds=\E+B,
    setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
    sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m,
    sgr0=\E[0;10m, smacs=\E[11m, smpch=\E[11m, smso=\E[7m,
    smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
    u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,

$

The '\E' notation refers to the ESC character.

'\ E'符号表示ESC字符。

Failing that, you could look up the standard itself.

如果做不到这一点,你可以查看标准本身。

#2


Tweaking the TERM environment variable might make applications based on terminfo/termcap avoid using advanced escape sequences. (export TERM=dumb) I am not sure that's what you want, though.

调整TERM环境变量可能会使基于terminfo / termcap的应用程序避免使用高级转义序列。 (导出TERM =哑)但我不确定这是你想要的。