I'm trying to enable reverse video on bash / xterm such that the text is black but the foreground is white. But it's not working. Here's my command:
我正在尝试在bash / xterm上启用反向视频,使文本为黑色但前景为白色。但它不起作用。这是我的命令:
echo -n -e \\x1B\\x07maaa\\x1B[m
Any ideas why it's not behaving as expected?
任何想法为什么它没有按预期行事?
4 个解决方案
#1
In the example
在示例中
echo -n -e \\x1B\\x07maaa\\x1B[m
the \\x07m
cannot be correct, since that would be an ASCII BEL. Perhaps you meant something like this:
\\ x07m不能正确,因为那将是ASCII BEL。也许你的意思是这样的:
echo -n -e \\x1B[7maaa\\x1B[m
The \\x1B
is the escape character. All of the other characters are from the printable-ASCII range. This assumes that your echo
interprets escapes in that manner (bash's does).
\\ x1B是转义字符。所有其他字符都来自可打印的ASCII范围。这假设你的echo以这种方式解释转义(bash的确如此)。
#2
It will be far simpler to use bash
's printf
command (and as Thomas Dickey pointed out, you're using the wrong sequence to enable inverse video). Asking yourself how many backslashes you need to stack up is almost always the wrong question.
使用bash的printf命令会更简单(正如Thomas Dickey指出的那样,你使用了错误的序列来启用反向视频)。问你自己需要堆叠多少反斜杠几乎总是错误的问题。
# \e[7m starts inverse video
# \e[m (short for \e[0m) resets all video parameters to their default values
printf '\e[7maaa\e[m'
#3
Another way:
echo -n -e "\e[07mTEXT\e[0m"
Or:
printf "\e[07mTEXT\e[0m"
#4
More portable are
更便携的是
tput rev
for reverse mode and
反向模式和
tput sgr0
to clear reverse mode.
清除反向模式。
#1
In the example
在示例中
echo -n -e \\x1B\\x07maaa\\x1B[m
the \\x07m
cannot be correct, since that would be an ASCII BEL. Perhaps you meant something like this:
\\ x07m不能正确,因为那将是ASCII BEL。也许你的意思是这样的:
echo -n -e \\x1B[7maaa\\x1B[m
The \\x1B
is the escape character. All of the other characters are from the printable-ASCII range. This assumes that your echo
interprets escapes in that manner (bash's does).
\\ x1B是转义字符。所有其他字符都来自可打印的ASCII范围。这假设你的echo以这种方式解释转义(bash的确如此)。
#2
It will be far simpler to use bash
's printf
command (and as Thomas Dickey pointed out, you're using the wrong sequence to enable inverse video). Asking yourself how many backslashes you need to stack up is almost always the wrong question.
使用bash的printf命令会更简单(正如Thomas Dickey指出的那样,你使用了错误的序列来启用反向视频)。问你自己需要堆叠多少反斜杠几乎总是错误的问题。
# \e[7m starts inverse video
# \e[m (short for \e[0m) resets all video parameters to their default values
printf '\e[7maaa\e[m'
#3
Another way:
echo -n -e "\e[07mTEXT\e[0m"
Or:
printf "\e[07mTEXT\e[0m"
#4
More portable are
更便携的是
tput rev
for reverse mode and
反向模式和
tput sgr0
to clear reverse mode.
清除反向模式。