* Jeremie Le Hen <jere...@le-hen.org> [2009-12-01 23:00 +0100]: > Format escape sequences are fairly easy to understand (reading them is > another thing ;p) except the truncation/padding stuff. I've tried to > read and re-read the paragraphs regarding %=, %< and %= multiples times > successively, and that multiple times over the last months. But > honestly, I can't grasp the way it works.
Let me try, although I might miss some corner cases. In its simplest form, `%=` adds padding to your status string so that the string fills the width of the screen. If you have more than one `%=` in your string, the added spaces are distributed equally among the padding points. Example: "[%H]%=%-w(%n-%t)%+w%=[%d/%m %c]" With three windows and a 60-column display, you might get something like the following. I have marked the right edge of the screen with a vertical bar; it is not part of screen's output. [ori] 1 zsh (2-zsh) 3 zsh [08/12 10:39]| You can also add numbers to the padding escape, e.g. `%20=`. In that case, screen will make the part of the string from the beginning to the location of that escape take up the specified percentage of the screen. If the string is too short, spaces will be added. If the string is too long, it will be truncated (i.e. characters will be removed from the right of the string until it is short enough). If the number is negative, the reference point is calculated relative to the right side of the screen, not the left. [Caveat: when I tested this just now, the right-side alignments were not calculated correctly; they were too far to the left.] You can think of this form of the escape as saying "place this location in the string at a specific point on the screen" where the destination is defined as a percentage of the screen width. Example: "[%H]%5=%-w(%n-%t)%+w%50=[%d/%m %c]" Again, three windows, a 60-column display, and a bar to mark the edge of the screen. Note that the first point caused the hostname to be truncated, but the second point causes padding to be added. [or1 zsh (2-zsh) 3 zsh [08/12 10:45] | 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. Example: "[%H]%50=%-w(%n-%t)%+w%20=[%d/%m %c]" [ori] [08/12 10:48] | If you use a number that starts with zero, e.g. `%05=`, screen considers it to be an absolute number; a specific column on the screen. If the number is also negative, screen will count from the right side of the screen, not the left. Example: "[%H]%05=%-w(%n-%t)%+w%-05=[%d/%m %c]" Also of note here is that the string is always truncated by the edge of the screen. [ori]1 zsh (2-zsh) 3 zsh [08/1| If the number you use starts with a plus sign, e.g. `%+20=`, the spacing calculation starts from the last truncation/padding point, not the left edge of the screen. Note that percentages are calculated based on the _remaining_ space, not the total space. Example: "[%H]%-w(%n-%t)%+w%+50=[%d/%m %c]" [ori]1 zsh (2-zsh) 3 zsh [08/12 11:02] | Example: "[%H]%50=%-w(%n-%t)%+w%+50=[%d/%m %c]" [ori] 1 zsh (2-zsh) [08/12 11:02] | If you add an 'L' at the end of the number, screen will only add padding; it will not truncate strings. Example: "[%H]%0=%-w(%n-%t)%+w%50=[%d/%m %c]" 1 zsh (2-zsh) 3 zsh [08/12 11:07] | Example: "[%H]%0L=%-w(%n-%t)%+w%50L=[%d/%m %c]" [ori]1 zsh (2-zsh) 3 zsh [08/12 11:07] | If you use a '<' instead of a '=', it will behave almost exactly as above, but screen will only truncate strings. (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.) Example: "[%H]%0<%-w(%n-%t)%+w%50<[%d/%m %c]" 1 zsh (2-zsh) 3 zsh[08/12 11:15] | Finally, there's the `%>` escape. You must specify a number in this escape. 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 `%>` to the first truncation/padding point on the right of the `%>`. 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.) Example: "[%H]%-w%45>(%n-%t)%+w[%d/%m %c]" For these examples, I'm still using a 60-column display, but now there are 11 windows. [ori]1 zsh 2 zsh 3 zsh 4 zsh 5 zsh (6-zsh) 7 zsh 8 zs| Example: "[%H]%-w%45>(%n-%t)%+w[%d/%m %c]%-0=" zsh 3 zsh 4 zsh 5 zsh (6-zsh) 7 zsh 8 zsh 9 zsh 10 | Example: "[%H]%L=%-w%45>(%n-%t)%+w%-13=[%d/%m %c]" Note here that I'm using `%L=` after the hostname. It won't truncate anything by itself, but it serves to narrow the window of truncation for the `%>` escape. I'm using `%-13=` because the date and time part of the string will always be 13 characters long. [ori]sh 4 zsh 5 zsh (6-zsh) 7 zsh 8 zsh 9[08/12 11:26]| You can also add an 'L' to the `%>` escape, e.g. `%45L>`. That causes screen to put ellipses into the truncated string to show truncation. Example: "[%H]%L=%-w%45L>(%n-%t)%+w%-13=[%d/%m %c]" [ori]... 4 zsh 5 zsh (6-zsh) 7 zsh 8 zsh...[08/12 11:31]| 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. The most general-purpose approach I've found is to have adjacent truncation/padding points. Example: "[%H]%L=%=%-w%45L>(%n-%t)%+w%=%-13=[%d/%m %c]" [ori] 1 zsh (2-zsh) 3 zsh [08/12 11:38]| [ori]... 4 zsh 5 zsh (6-zsh) 7 zsh 8 zsh...[08/12 11:37]| > The icing on the cake would be to have the "%-w (%n-%t) %+n" centered > around the current window and not eating the outer parts when the space > in the middle is not large enough. I believe my final example will do what you want. -- ...computer contrarian of the first order... / http://aperiodic.net/phil/ PGP: 026A27F2 print: D200 5BDB FC4B B24A 9248 9F7A 4322 2D22 026A 27F2 --- -- This thing all things devours: Birds, beasts, trees, flowers; Gnaws iron, bites steel; Grinds hard stones to meal; Slays king, ruins town, And beats high mountain down. ---- --- -- _______________________________________________ screen-users mailing list screen-users@gnu.org http://lists.gnu.org/mailman/listinfo/screen-users