本文介绍了Bash 文本绝对定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何做输出的绝对定位?非常类似于 Linux 首次启动时,您会看到以下内容:

How can you do absolute positioning of output? Very similar to like when Linux first boots and you see the following:

Starting process blah blah blah                              [   OK   ]

推荐答案

您可以在 /etc/init.d 中看到许多 Linux 发行版中用于生成那些 [ OK ] 的代码/functions

You can see the code used to produce those [ OK ] in many Linux distributions in /etc/init.d/functions

$ grep echo_ /etc/init.d/functions
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
$

经过检查,您会发现这些函数使用了ANSI 转义序列.

Upon inspection, you will see that those function use ANSI escape sequences.

echo_success() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  ...
  return 0
}

MOVE_TO_COL="echo -en \033[${RES_COL}G"

这篇关于Bash 文本绝对定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 10:20
查看更多