Linux screen tool configuration (for string escape)

Source: Internet
Author: User
Tags month name

The GNU screen tool is a good tool. If you need to log on to the server frequently or frequently, screen may be an indispensable tool.
This article mainly discusses how to customize the content of the status bar in the screen configuration script, that is, the content customization of hardstatus.
The problems discussed in this article have little guidance for the use of the screen tool, and can even be considered as a boring problem, therefore, if you want to learn how to get started with screen, you do not need to continue reading it. You can refer to other introductions from many comrades on the Internet.

For the comrades who use Putty to connect to the server, there are generally three methods to get multiple shells:

  1. The most direct and simple method is to open multiple putyy connection terminals. This is the most common method.
  2. Install the X-window server locally. Generally, it is xming or xwin server. Use a putty to log on to the system, and then use xterm. You can open "unlimited" terminals.
  3. With scrren, you can open up to 10 terminals at the same time each time you log on to putty.

From the above description, screen does not show any advantages. The main reason is that it has not been expanded. The specific search on the Internet shows how the screen works. This is not the focus of this article.

I want to say that when using the screen tool, she can display a status or caption column at the bottom of the window like a program on the graphical interface, as shown in:

 

This status bar can be used to display many things. You can customize the content. This article mainly discusses how to customize the following hardstatus bar or caption bar.

First, we need to explain why the caption column or the hardstatus column is required. Isn't that true?

There is no complete line. There is no big difference with not in use. If there is such a column, it takes up a little area of display, making the display area smaller.

So why?

This is mainly because it is easy to use, because we use the putty logon interface, which is the same as the interface after we log on to the screen.

This makes it inconvenient for us to determine whether we are on the putty login interface? Or is it already under the control of screen?

When we work in screen, we have a place to remind you, "you are on screen now, and CTL + A should not be used randomly." How can this problem be solved?

This is the purpose of my research on writing the hardstatus column, or the starting point.

How do I write it?

I didn't know how to do it myself, but I guess I just copied and pasted some examples in Chinese, so I thought it was difficult to set the hardstatus column.

However, after reading the reference materials in the original English text, I found that there is nothing. It is quite simple, but it is a little troublesome.

For example, a popular configuration on the internet is as follows:

Caption always "%? % F % {-B 4 W }%:%{-B BB }%? % H | % L | % m-% d % C | %? % F % {-B 4 W }%? % L = %-LW % 45 >%{-B W4} % N % F * % T % {-} % + LW %-0 <"

The bird in the line above does not look like a human eye? Is my mind broken?

However, the introduction on the Internet ends, and the subsequent Chinese posts are basically absent. it is no wonder that the habits of the Chinese people are pragmatic. The use of this thing is limited. Some people have already sorted it out and can use it. Why should we study it?

I searched for the introduction in English and found many articles about caption or hardstatus. the main reason is screen's own documents. the content of the "string escape" section in this document is summarized as follows. The content of this section mainly explains how to write the syntax.

In general, refer to the two tables below. What kind of hardstatus column or caption column can be written will not be scared by other statements .:

% The Escape Character Mark itself. All the characters with special meanings start with this %.
A "Am" or "PM"
A "Am" or "PM"
C Current Time hh: mm (in 24-hour format)
C Current Time hh: mm (in 12-hour format)
D Date Number
D Week number
F Flags of the Windows (unknown)
F %? The expression value is true.
H Hardstatus of the current window
H System name, that is, hostname
L Current System Load
M Month number
M Month name (Jan ?)
N Window Number (starting from 0). If it is an expression like % 3n, it indicates that the window number occupies three places.
S The number of seconds in the time representation.
S Second name
U All other users in the current window
W Number and name of all windows. If it is-W, it indicates all windows from 0 to before the current window, + W indicates all the windows from the next to the last window of the current window.
W Number and name of all Windows except the current window
Y The last two digits of the Year Number
Y Full name of year
? The normal expression for condition determination is %? XXXXX %? : Yyyyy. If Xxxxx is not an empty string, Xxxxx is displayed; otherwise, yyyyy is displayed.
= % = Indicates the rightmost end of the hardstatus column of the string before filling. % 50 = indicates filling at 50% of the hardstatus column. Note that the characters filled are spaces.

 

You can also use expressions such as % + 20 = and %-30 =. These two expressions indicate filling 20% spaces from the end position of the last fill, respectively,

Then, the following string is displayed (if there is no filling before, it is no different from % 20 =), and the space is filled to 30% from the right side.

Note that the expression like "% N: % T % 5 = % H" is obviously % N: the output of % T should be greater than % 5 of the length of the hardstatus column,

However, after % 5 is filled, % H is written from % 5 of the column length. Therefore, the preceding content is overwritten by the following content. This is called truncation.

< This escape character is generally used at the end of the string of hardstatus. It serves the same purpose as the following %>,

 

Is used for scrolling. If the displayed content exceeds the length of the hardstatus column, the entire displayed content is rolled forward, make sure that the last content is displayed,

Obviously, the front part of the display content is rolled out of the display area and cannot be displayed.

Generally, you do not need to carefully consider the meaning of this escape character. It is mainly used with the following %>. and when used together with %>, the rolling feature is changed,

It is no longer simply % <so that the end is always displayed, but changed to %>, so that the specific part is rolled to a specific proportion.

So why should we use % <instead of %>? The main definition of %> is,

If scrolling exists, the rolling attribute is changed to scroll a specific part to a specific proportion. However, if not, %> does not work, but % <does, the rolling attribute is provided.

> This is a very useful feature. For example, there is a very good configuration like this:

 

Hardstatus string "%-w % {= BW}% 50>% N % T % {-} % + w % <"

There is a % 50>, and the front is %-W, which indicates the number of the window from 0 to the current window plus title.
After %-W is displayed, add another % N % T. That is to say, the number and title of this window are also displayed.
However, this % 50> is inserted in the middle. What does this mean?
Because we may have created many windows, so that the display of the light %-W has exceeded the range of the entire hardstatus,
When % N % T is displayed again, the display range of the entire bar is exceeded,
It also needs to be truncated. % 50> is actually a rolling hardsatus column.
As you can imagine, when the hardstatus column is filled with %-W,
If % N % T is displayed again, % N % T is out of the display range and cannot be seen.
At this time, we apply % 50> to scroll %-W to the place in the hardstatus column 50%.
Apparently, some of the first part of %-W is truncated, but % N % T is displayed from % 50.
I understand. The role of this symbol is hard to describe, but it is visually easy to understand. It is the role of rolling the harstatus column. It is just rolling.
You can use an expression such as % 50l>, which indicates that,
If there is a scroll, if the content is not displayed because of scrolling... To indicate that the content is not displayed. It may be displayed on the right side of the left.

{XX} The content in braces is to set attributes or set colors. For more information, see the following new table.

The following table describes how to set attributes, that is, settings related to the color of text.

{+} Add this property
{-} This attribute is reduced. When used separately, it indicates that the setting value before the last attribute change is returned.
{!} Reverse the current attribute
{=} Change the current attribute. Apply the attribute specified here.
D Dim Effect
U Underline
B Simhei
R Reverse
S Highlighted
B Flashing Effect
K Black
R Red
G Green
Y Yellow
B Blue
M Pinhong
C Blue-green
W White
D Default color
. Do not change color
  Note that the color settings include the foreground color and background color, that is, the font color and background color.

 

% {= BM}. This expression indicates that the background color is changed to B, and the foreground color is changed to M. (in this Order) if only one color is specified, instead of two colors, the foreground color is changed. If yes !, You can also use '.' to indicate that the color is not changed. For example, % {= B.} indicates that the background color is changed without changing the foreground color.

  Examples:
  % {+ B R} indicates that the background color is set to the red color of the black body.
  % {= YD} indicates that the background color is yellow and the foreground color is the default color.
  % {= Y.} the background color is set to yellow, and the foreground color remains unchanged.
   

The two tables above should have been very detailed and there should be no problem with the vast majority of settings.

Finally, an example is provided.

I think the better one is:

Hardstatus string "%-w % {= BW} % 50>% N % T % {-} % + w % <"

The above is very simple and practical. There are not many system load information and other things, only display all the window names in the system and highlight the current window name. but I think this is very good, concise and practical.

As follows:

Reference:

Http://www.gnu.org/software/screen/manual/screen.html#Message-Line

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.