使 WIN10 命令行传播 WSL 颜色
Make WIN10 command line propagate WSL colors
每当我打开命令提示符并使用命令序列时
wsl
ls
输出的颜色很漂亮。
但是,如果我在一个命令中执行相同的操作,
wsl ls
输出完全没有颜色。
是否缺少某些设置?甚至可以使输出继承 WSL 颜色吗?
使用 WSL2 和 Windows10 构建 19041.867
使用 cmd 控制台,ls
将其检测为不支持 ANSI 颜色的终端输出,因此默认情况下禁用彩色输出。在 Windows 10 上,cmd 控制台支持 ANSI 的颜色序列,因此您可以强制 ls
在这种情况下为其输出着色:
wsl ls --color=always
编辑: 另一种方法是为 Windows 控制台添加一个包含 VT 功能的 terminfo 条目(参见 tic
、toe
, terminfo
).这需要一些研究,但这种方式将为 Windows 控制台下的每个 wsl 命令提供彩色输出。
WSL terminfo 数据库中有 Windows ANSI 控制台的现有条目:
$ toe -a | grep Windows
ansi-nt Microsoft Windows NT console POSIX ANSI mode
$ infocmp ansi-nt
# Reconstructed via infocmp from file: /usr/share/terminfo/a/ansi-nt
ansi-nt|psx_ansi|Microsoft Windows NT console POSIX ANSI mode,
am, bw, msgr,
cols#80, it#8, lines#25,
bel=^G, clear=\E[2J, cr=\r, cub1=^H, cud1=\n, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, ed=\E[J, el=\E[K,
home=\E[H, ht=^I, ind=\E[S, kbs=^H, kcub1=\E[D, kcud1=\E[V,
kcuf1=\E[C, kcuu1=\E[A, nel=\r\E[S, rc=\E[u, rev=\E[7m,
ri=\E[T, rmso=\E[m, sc=\E[s, sgr0=\E[0m, smso=\E[7m,
看来我们只需要为 Windows 10 添加颜色#8。自从我上次使用 tic
以来这么多年了,我必须为此进行测试和试验。
每当我打开命令提示符并使用命令序列时
wsl
ls
输出的颜色很漂亮。
但是,如果我在一个命令中执行相同的操作,
wsl ls
输出完全没有颜色。
是否缺少某些设置?甚至可以使输出继承 WSL 颜色吗?
使用 WSL2 和 Windows10 构建 19041.867
使用 cmd 控制台,ls
将其检测为不支持 ANSI 颜色的终端输出,因此默认情况下禁用彩色输出。在 Windows 10 上,cmd 控制台支持 ANSI 的颜色序列,因此您可以强制 ls
在这种情况下为其输出着色:
wsl ls --color=always
编辑: 另一种方法是为 Windows 控制台添加一个包含 VT 功能的 terminfo 条目(参见 tic
、toe
, terminfo
).这需要一些研究,但这种方式将为 Windows 控制台下的每个 wsl 命令提供彩色输出。
WSL terminfo 数据库中有 Windows ANSI 控制台的现有条目:
$ toe -a | grep Windows
ansi-nt Microsoft Windows NT console POSIX ANSI mode
$ infocmp ansi-nt
# Reconstructed via infocmp from file: /usr/share/terminfo/a/ansi-nt
ansi-nt|psx_ansi|Microsoft Windows NT console POSIX ANSI mode,
am, bw, msgr,
cols#80, it#8, lines#25,
bel=^G, clear=\E[2J, cr=\r, cub1=^H, cud1=\n, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, ed=\E[J, el=\E[K,
home=\E[H, ht=^I, ind=\E[S, kbs=^H, kcub1=\E[D, kcud1=\E[V,
kcuf1=\E[C, kcuu1=\E[A, nel=\r\E[S, rc=\E[u, rev=\E[7m,
ri=\E[T, rmso=\E[m, sc=\E[s, sgr0=\E[0m, smso=\E[7m,
看来我们只需要为 Windows 10 添加颜色#8。自从我上次使用 tic
以来这么多年了,我必须为此进行测试和试验。