Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
880 views
in Technique[技术] by (71.8m points)

bash - Set or change vertical position of the cursor

As far as I know, it is possible to move the cursor to the left using the backspace sequence in an echo. But is there any possibility to change the vertical position of the cursor, using an echo?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This section describes the ANSI escape sequences:

Examples:

echo -en "33[s33[7B33[1;34m 7 lines down violet 33[u33[0m"
echo -en "33[s33[7A33[1;32m 7 lines up green 33[u33[0m"

And this section describes the tput utility:

For a demonstration, see The floating clock in your terminal:

An example script taken from http://www.cyberciti.biz/tips/spice-up-your-unix-linux-shell-scripts.html:

#!/bin/bash

tput clear      # clear the screen

tput cup 3 15   # Move cursor to screen location X,Y (top left is 0,0)

tput setaf 3    # Set a foreground colour using ANSI escape
echo "XYX Corp LTD."
tput sgr0

tput cup 5 17
tput rev        # Set reverse video mode
echo "M A I N - M E N U"
tput sgr0

tput cup 7 15; echo "1. User Management"
tput cup 8 15; echo "2. Service Management"
tput cup 9 15; echo "3. Process Management"
tput cup 10 15; echo "4. Backup"

tput bold       # Set bold mode 
tput cup 12 15
read -p "Enter your choice [1-4] " choice

tput clear
tput sgr0
tput rc

tput example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...