Improve string pad examples and add a cross-reference

The old examples were not really showcasing that it's nice for aligning text.
This commit is contained in:
Johannes Altmanninger 2020-09-28 18:42:02 +02:00
parent 3002c88f44
commit 286ad97cbd
2 changed files with 12 additions and 5 deletions

View File

@ -44,6 +44,8 @@ Valid format specifiers are taken from the C library function ``printf(3)``:
Conversion can fail, e.g. "102.234" can't losslessly convert to an integer, causing printf to print an error. If you are okay with losing information, silence errors with `2>/dev/null`.
A number between the ``%`` and the format letter specifies the width. The result will be left-padded with spaces.
Backslash Escapes
-----------------
printf also knows a number of backslash escapes:

View File

@ -34,17 +34,22 @@ Examples
::
>_ string pad -w 10 abc
>_ string pad -w 10 abc abcdef
abc
abcdef
>_ string pad --right --char=🐟 "fish are pretty" "rich. "
fish are pretty
rich. 🐟🐟🐟🐟
>_ string pad -w 6 -c- " | " "|||" " | " | string pad -r -w 9 -c-
--- | ---
---|||---
--- | ---
>_ string pad -w$COLUMNS (date)
# Prints the current time on the right edge of the screen.
See Also
--------
- The :ref:`printf <cmd-printf>` command can do simple padding, for example ``printf %10s\n`` works like ``string pad -w10``.
.. END EXAMPLES