Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 设置或更改光标的垂直位置_Bash - Fatal编程技术网

Bash 设置或更改光标的垂直位置

Bash 设置或更改光标的垂直位置,bash,Bash,据我所知,可以使用回音中的退格序列将光标向左移动。但是是否有可能使用回音改变光标的垂直位置?本节介绍ANSI转义序列: 示例: echo -en "\033[s\033[7B\033[1;34m 7 lines down violet \033[u\033[0m" echo -en "\033[s\033[7A\033[1;32m 7 lines up green \033[u\033[0m" 本节介绍了tput实用程序: 有关演示,请参见终端中的浮动时钟: tput cuu 1

据我所知,可以使用回音中的退格序列将光标向左移动。但是是否有可能使用回音改变光标的垂直位置?

本节介绍ANSI转义序列:

示例:

echo -en "\033[s\033[7B\033[1;34m 7 lines down violet \033[u\033[0m"
echo -en "\033[s\033[7A\033[1;32m 7 lines up green \033[u\033[0m"
本节介绍了tput实用程序:

有关演示,请参见终端中的浮动时钟:

tput cuu 1             # move cursor up 1 position
nudgeup=`tput cuu 2`   # save it for later
nudgeleft=`tput cub 2`   
echo -n $nudgeup $nudgeleft
示例脚本取自:


使用
echo
将限制您使用特定的终端类型。最好使用
tput

tput cup 10 4; echo there
将光标放在第10行第4列,并在该位置打印“there”


对于更基本的移动,您有
tput cub1
向左移动、
tput cuf1
向右移动、
tput cuu1
向上移动和
tput cud1
向下移动光标。

是的,正如miku所指出的,ANSI终端逸出,或者一个稍微清洁的tput应该可以在任何终端上工作:

tput cuu 1             # move cursor up 1 position
nudgeup=`tput cuu 2`   # save it for later
nudgeleft=`tput cub 2`   
echo -n $nudgeup $nudgeleft
请参见BASH提示符howto中ANSI部分之后的几个部分


tput还返回一个退出代码,告诉您是否有不受支持的内容。

请参阅:…和另一个tldp的演示,该演示包含不完整的答案。