Warning: Undefined array key "stylesheets" in /home/public/screen/inc/StyleUtils.php on line 102

Table of Contents

Truncation/Padding Escapes

screen has a number of string escapes it uses for building various strings. Most are replaced by text when the string is built, but the =, <, and > escapes control a string's formatting by either adding spaces or deleting characters.

Examples

These escapes are mostly used in formatting hardstatus/caption lines. The examples on this page all demonstrate uses of the truncation/padding escapes in the caption line for a 60-column screen window. For every example string, two status lines are shown: one for a screen session with three windows (so the window list is shorter than the caption length), and one for a screen session with 11 windows (so the window list is longer than the caption length).

The base from which all the examples vary is the caption string “[%H]%-w(%n-%t)%+w[%d/%m %c]”, which displays the hostname, a list of windows with the current window in parentheses, and the date and time.

caption always "[%H]%-w(%n-%t)%+w[%d/%m %c]"
[mithrandir]0 zsh  (1-zsh)  2 zsh[09/12 12:00]
[mithrandir]0 zsh  1 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 zs

The ''='' Escape

No Arguments

If the = escape is specified with no arguments, e.g. %=, screen will replace it with enough spaces to make the status string exactly as wide as the display. If more than one such escape is present in the string, screen will split the spaces evenly between all the escapes.

caption always "[%H]%=%-w(%n-%t)%+w[%d/%m %c]"
[mithrandir]              0 zsh  (1-zsh)  2 zsh[09/12 12:00]
[mithrandir] 0 zsh  1 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 z
caption always "[%H]%=%-w(%n-%t)%+w%=[%d/%m %c]"
[mithrandir]       0 zsh  (1-zsh)  2 zsh       [09/12 12:00]
[mithrandir] 0 zsh  1 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 z

Percentage Arguments

If a number is given as a parameter to the = escape, screen uses that number as a percentage of the display width and either adds spaces at the point or removes characters to the left of the point in order to place that point at the specified location on the screen.

caption always "[%H]%10=%-w(%n-%t)%+w%50=[%d/%m %c]"
[mithr0 zsh  (1-zsh)  2 zsh   [09/12 12:00]
[mithr0 zsh  1 zsh  2 zsh  3 z[09/12 12:00]

Note that you can do silly things like putting a smaller size later in the string than a larger size, like %H%50=%w%20= and screen will happily pad (or truncate) the string to the first size, add any additional escapes, and then truncate down to the smaller size.

caption always "[%H]%50=%-w(%n-%t)%+w%20=[%d/%m %c]"
[mithrandir][09/12 12:00]
[mithrandir][09/12 12:00]

Absolute Placement Arguments

If the numeric parameter starts with a zero, screen considers it to be an absolute position, rather than a percentage. Thus, while %5= refers to a point 5% from the left of the screen, %05= refers to the fifth character in the string.

caption always "[%H]%020=%-w(%n-%t)%+w%050=[%d/%m %c]"
[mithrandir]        0 zsh  (1-zsh)  2 zsh         [09/12 12:
[mithrandir]        0 zsh  1 zsh  2 zsh  3 zsh  4 [09/12 12:

Number Signs

The numeric parameter may be preceeded by either a plus sign or a minus sign. If a minus sign is used, screen calculates the distance from the right side of the screen, not the left. If a plus sign is used, screen calculates the distance from the last truncation/padding point. Note that percentages are calculated based on the remaining space, not the total space.

Note the some versions of screen (including at least screen 4.00.03) do not calculate right-aligned numbers as percentages; they always consider them to be absolute values, even without a leading zero.

caption always "[%H]%25=%-w(%n-%t)%+w%-25=[%d/%m %c]"
[mithrandir]   0 zsh  (1-zsh)  2 zs[09/12 12:00]            
[mithrandir]   0 zsh  1 zsh  2 zsh [09/12 12:00]            
caption always "[%H]%50=%-w(%n-%t)%+w%+50=[%d/%m %c]"
[mithrandir]                  0 zsh  (1-zsh) [09/12 12:00]
[mithrandir]                  0 zsh  1 zsh  2[09/12 12:00]

The ''L'' Flag

If the numeric parameter is followed by an L, screen will only add padding at that point. If truncation would otherwise be needed, screen will do nothing.

caption always "[%H]%0L=%-w(%n-%t)%+w%60L=[%d/%m %c]"
[mithrandir]0 zsh  (1-zsh)  2 zsh   [09/12 12:00]
[mithrandir]0 zsh  1 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 zs

The ''<'' Escape

The < escape takes exactly the same set of arguments as the = escape, but it's the opposite of using the L flag with the = escape: it will only truncate strings; if padding would otherwise be needed, the < escape will do nothing.

In other words, you have three truncation/padding choices: %= will try to place the escape at exactly the specified point; %L= will place the escape at the specified point only if it can do it by adding spaces to the string; and %< will place the escape at the specified point only if it can do it by truncating the string.

caption always "[%H]%0<%-w(%n-%t)%+w%50<[%d/%m %c]"
0 zsh  (1-zsh)  2 zsh[09/12 12:00]
0 zsh  1 zsh  2 zsh  3 zsh  4 [09/12 12:00]

The ''>'' Escape

Numeric Arguments

The > escape requires a numeric parameter, e.g. %20>. When screen must truncate a string that contains a > escape, it will truncate the string from both ends as necessary to place the escape a percentage of the way into the truncation space, where the percentage is the number specified as a parameter. The “truncation space” extends from the first truncation/padding point on the left of the > escape to the first truncation/padding point on the right of the > escape. If there's no such point on the left, the beginning of the string is used. If there's no such point on the right, the escape is ignored. (i.e. the right edge of the screen is not considered a proper truncation point.)

caption always "[%H]%-w%45>(%n-%t)%+w[%d/%m %c]"
[mithrandir]0 zsh  (1-zsh)  2 zsh[09/12 12:00]
[mithrandir]0 zsh  1 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 zs
caption always "[%H]%-w%45>(%n-%t)%+w[%d/%m %c]%-0="
[mithrandir]0 zsh  (1-zsh)  2 zsh[09/12 12:00]
 zsh  2 zsh  3 zsh  4 zsh  (5-zsh)  6 zsh  7 zsh  8 zsh  9 z

It can often be useful to narrow the boundaries of the > escape's truncation space, to avoid problems like the last example's removal of the hostname. An easy way to do this is to add a %L= at the desired boundary.

caption always "[%H]%L=%-w%45>(%n-%t)%+w%-13=[%d/%m %c]"
[mithrandir]0 zsh  (1-zsh)  2 zsh              [09/12 12:00]
[mithrandir] 3 zsh  4 zsh  (5-zsh)  6 zsh  7 zs[09/12 12:00]

The ''L'' Flag

If the numeric parameter is followed by a L, screen will add ellipses to mark where truncation has taken place.

caption always "[%H]%L=%-w%45L>(%n-%t)%+w%-13=[%d/%m %c]"
[mithrandir]0 zsh  (1-zsh)  2 zsh              [09/12 12:00]
[mithrandir]...zsh  4 zsh  (5-zsh)  6 zsh  7...[09/12 12:00]
[mithrandir]0 zsh  1 zsh  (2-zsh)  3 zsh  4 ...[09/12 12:00]

Interference with Padding

The > escape only kicks in if a string is truncated; if padding is needed, not only does it not do anything, it appears to interfere with padding insertions (at least as of screen 4.00.03). One general-purpose workaround to this problem is to have adjacent truncation/padding points at the boundaries of the > escape's truncation space.

caption always "[%H]%L=%=%-w%45L>(%n-%t)%+w%=%-13=[%d/%m %c]"
[mithrandir]       0 zsh  (1-zsh)  2 zsh       [09/12 12:00]
[mithrandir]...zsh  4 zsh  (5-zsh)  6 zsh  7...[09/12 12:00]
[mithrandir] 0 zsh  1 zsh  (2-zsh)  3 zsh  4...[09/12 12:00]