Bash text absolute positioning

纵然是瞬间 提交于 2019-12-11 09:17:16

问题


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   ]

回答1:


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() {
$

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"



回答2:


You can use "tput cup 10 10" to move the cursor to desired location. In this case 10th column and 10th row. Check out the tput's man page.



来源:https://stackoverflow.com/questions/20381937/bash-text-absolute-positioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!