如何使watch命令解释vt100序列? [英] How can I make the watch command interpret vt100 sequences?

查看:88
本文介绍了如何使watch命令解释vt100序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下简单示例(显示为红色):

echo -e "\033[31mHello World\033[0m"

Consider this simple example (which displays in red):

echo -e "\033[31mHello World\033[0m"

它在终端上正确显示为红色.现在考虑:

watch echo -e "\033[31mHello World\033[0m"

It displays on the terminal correctly in red. Now consider:

watch echo -e "\033[31mHello World\033[0m"

它不显示颜色.

注意:我知道编写一个通过清除和重新运行来模仿基本行为的循环很容易.但是,清除操作会导致屏幕闪烁,这在手表情况下不会发生

Note: I am aware that it is easy to write a loop that mimics the basic behavior by clearing and rerunning. However, the clear operation causes the screen to flash, which does not happen under watch

最初,这个问题指定了转义序列而不是vt100序列,但这并不是我真正想要的,并用单引号解决了.

Originally this question specified escape sequences rather than vt100 sequences, but that is not really what I am after, and was solved with single quotes.

推荐答案

watch的最新版本支持颜色.在问题示例的特定情况下,您将需要使用额外的引号级别来保留引号和转义符:

More recent versions of watch support color. You will need to use an extra level of quoting to preserve the quotes and escapes in the particular situation of the example in the question:

watch 'echo -e "\033[31mHello World\033[0m"'

来自man watch:

  -c, --color
          Interpret ANSI color sequences.

以前:

来自man watch:

从程序输出中去除非打印字符.使用"cat -v" 如果您想查看它们,可以将其作为命令管道的一部分.

Non-printing characters are stripped from program output. Use "cat -v" as part of the command pipeline if you want to see them.

但是它们没有得到解释,所以我认为没有任何办法.

But they don't get interpreted, so I don't think there's any way.

这篇关于如何使watch命令解释vt100序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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