简体   繁体   English

'watch' 没有解释隐含的 'reset' 颜色代码 `^[m`

[英]'watch' is not interpreting the implicit 'reset' color code `^[m`

It appears that watch is not interpret the implicit 'reset' color code ^[m .看来watch没有解释隐含的“重置”颜色代码^[m It does interpret the explicit code ^[0m .它确实解释了显式代码^[0m

Does anyone know how to fix this?有谁知道如何解决这一问题? Or does it sound like a bug and I need to contact the maintainers of watch ?或者这听起来像一个错误,我需要联系watch的维护者?

Why I'm asking:为什么我要问:

I'm using watch with git log , and git log uses implicit resets ^[m .我将watchgit log一起使用,而git log使用隐式重置^[m

Example:例子:

$ watch -c git log --oneline --decorate --source --graph --color=always

显示问题

What it should look like is:它应该是什么样子:

$ git log --oneline --decorate --source --graph --color=always

预期的

Investigation调查

If we don't include the -c ( --color ) option on watch , we can see that the ANSI escape codes are there:如果我们不在watch包含-c ( --color ) 选项,我们可以看到 ANSI 转义码在那里:

Every 2.0s: git log --oneline --decorate --source --graph --color=always                                                                                                                                                                               Fri Sep 28 08:17:42 2018

* ^[33m9db218b^[m       HEAD^[33m (^[m^[1;36mHEAD^[m^[33m -> ^[m^[1;32mmaster^[m^[33m, ^[m^[1;33mtag: v0.8.0b5^[m^[33m, ^[m^[1;31morigin/master^[m^[33m, ^[m^[1;31morigin/HEAD^[m^[33m)^[m Doc updates for v0.8.0b5 release
* ^[33mfd342d9^[m       HEAD Update changelog [ci skip]
* ^[33md1af865^[m       HEAD Update changelog
*   ^[33m70889fa^[m     HEAD Merge branch 'testing-updates' into 'master'

There's a lot going on in the above example - let's simplify it:上面的例子中发生了很多事情——让我们简化一下:

Prove that we're escaping things correctly:证明我们正确地转义:

$ echo -e "\033[33myellow\033[mnormal"

简单的回声颜色转义

Send it to watch发送watch

Note: the -e arg on echo is not parsed because we're quoting things.注意: echo上的-e arg 未被解析,因为我们正在引用内容。 watch now handles the color codes. watch现在处理颜色代码。

$ watch -c 'echo -e "\033[33myellow\033[mnormal"'

手表因重置代码而失败

Remove the -c flag from watchwatch删除-c标志

$ watch 'echo -e "\033[33myellow\033[mnormal"'
Every 2.0s: echo -e "\033[33myellow\033[mnormal"      Fri Sep 28 08:29:26 2018

-e ^[33myellow^[mnormal

This looks as expected.这看起来像预期的那样。

Using the explicit ^[0m reset code works使用显式^[0m重置代码有效

$ watch -c 'echo -e "\033[33myellow\033[0mnormal"'

在此处输入图片说明

Versions版本

Primarily tested under WSL: Window 10 Pro, v1803, build 17134.286主要在 WSL 下测试:Window 10 Pro, v1803, build 17134.286

$ watch -v
watch from procps-ng 3.3.10
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:        16.04
Codename:       xenial
$ uname -a
Linux redacted-hostname 4.4.0-17134-Microsoft #285-Microsoft Thu Aug 30 17:31:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
$ git --version
git version 2.7.4

Also tested using PuTTY to a linux machine.还在 Linux 机器上使用 PuTTY 进行了测试。 Same version information as above, just not using WSL.与上面相同的版本信息,只是不使用 WSL。

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

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