Several operations on the terminal in Linux-Linux general technology-Linux technology and application information. The following is a detailed description. Of course, if you use some existing libraries (such as ncurses), there will be no information in this article. Now let's assume we have to build our own wheels.
1. Obtain the width and height of the terminal:
# Include
Struct winsize sz;
Ioctl (1, TIOCGWINSZ, & sz );
Printf ("Width = % d \ n, Height = % d \ n", (int) sz. ws_col, (int) sz. ws_row );
The first parameter 1 of ioctl is the file descriptor (file number) of the terminal to be obtained. If it points to a file other than the terminal, ioctl function will fail.
2. Show/hide the cursor (as shown here): use two escape sequences
"\ 033 [? 25l ": Hide the cursor (the last one is the letter l, not the number 1)
"\ 033 [? 25 h ": displays the cursor
3. Terminal mouse support
Xterm-compatible terminals support mouse operations, which are disabled by default. Use the control sequence "\ 033 [? 1000 h "enabled, with" \ 033 [? 1000l "disabled.
After the mouse report mode is started, when the mouse moves to the terminal (Press/release the mouse key, scroll wheel), the terminal can read the escape sequence of six bytes. [M B x y. From B, you can know the current event (which mouse key is pressed/released, and which direction the scroll wheel is scroll to), and from (x, y) you can see the current mouse position. For details, see "man console_codes" (page search for mouse)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service