简体   繁体   中英

How can output be directed to specific coordinates in the linux terminal?

To be more specific, I am looking for an equivalent to the Windows API function: WriteConsoleOutputCharacter. I know this style of direct output is possible, as I have seen the behaviour used before in the time that I have used Linux. However, I am still a baby when it comes to Linux specific C libraries, and have not been able to ascertain any clues as to where I may find such functionality. Any assistance would be appreciated.

Check out ncurses library.

It allows you to create some text-based UI in terminal. It is more than you asked, but if you need more than only this one function it may be best option for you.

You can use the ANSI control sequence

Say, following will print 'ddd' string 3 lines above the prompt in bash

echo -e "\e[3Addd"

这条线将时钟放在终端的右上方(来自commandlinefu.com)

while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM