2014-12-23 22:50:09 +01:00
|
|
|
---
|
2014-12-24 14:04:40 +01:00
|
|
|
title: Examples
|
2021-05-26 21:13:21 +02:00
|
|
|
permalink: /examples.html
|
|
|
|
redirect_from:
|
|
|
|
- /examples.shtml
|
|
|
|
longContent: true
|
|
|
|
created_at: 1999-04-06
|
|
|
|
last_modified_at: 2021-02-17 20:58:16 +0100
|
2014-12-23 22:50:09 +01:00
|
|
|
---
|
|
|
|
|
2015-05-12 21:50:01 +02:00
|
|
|
# Examples
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Remember, *boxes* is designed to be tied to your editor as a [text filter](docs/filters.html). So these examples assume
|
|
|
|
you need only push a single key (or at least very few) in order to call *boxes*. Don't be worried by seemingly long
|
|
|
|
argument lists - you'll only have to type them once.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
Unless stated otherwise, the input used for these examples is the following:
|
|
|
|
|
|
|
|
Different all twisty a
|
|
|
|
of in maze are you,
|
|
|
|
passages little.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2
|
|
|
|
text="Default action" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes`
|
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/* Different all twisty a */
|
|
|
|
/* of in maze are you, */
|
|
|
|
/* passages little. */
|
|
|
|
/**************************/
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Draws a standard box of the first valid design found in your config file. If you have the config file as it comes with
|
|
|
|
the *boxes* distribution, you get a "C" box, as you can see above.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="with-tools"
|
|
|
|
text="Combining with other tools" %}
|
2021-02-17 20:58:16 +01:00
|
|
|
|
|
|
|
As a text filter, *boxes* can be combined easily with other tools, for example *figlet* and *lolcat*:
|
|
|
|
|
|
|
|
`figlet "boxes . . . !" | lolcat -f | boxes -d unicornthink`
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
<img src="{{ site.baseurl}}/images/example-with-tools.png" class="img-fluid" alt="boxes with figlet and lolcat" width="457" height="304" />
|
2021-02-17 20:58:16 +01:00
|
|
|
|
|
|
|
Note: *lolcat* is supported since *boxes* v2.0.0.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="design"
|
|
|
|
text="Choosing a different design" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d parchment`
|
|
|
|
|
|
|
|
________________________
|
|
|
|
/\ \
|
|
|
|
\_|Different all twisty a|
|
|
|
|
|of in maze are you, |
|
|
|
|
|passages little. |
|
|
|
|
| ___________________|_
|
|
|
|
\_/_____________________/
|
|
|
|
|
|
|
|
The **-d** *design_name* option selects another design from your config file.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="position"
|
|
|
|
text="Positioning of text inside box" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d diamonds -a hcvc`
|
|
|
|
|
|
|
|
/\ /\ /\
|
|
|
|
/\//\\/\ /\//\\/\ /\//\\/\
|
|
|
|
/\//\\\///\\/\//\\\///\\/\//\\\///\\/\
|
|
|
|
//\\\//\/\\///\\\//\/\\///\\\//\/\\///\\
|
|
|
|
\\//\/ \/\\//
|
|
|
|
\/ \/
|
|
|
|
/\ Different all twisty a /\
|
|
|
|
//\\ of in maze are you, //\\
|
|
|
|
\\// passages little. \\//
|
|
|
|
\/ \/
|
|
|
|
/\ /\
|
|
|
|
//\\/\ /\//\\
|
|
|
|
\\///\\/\//\\\///\\/\//\\\///\\/\//\\\//
|
|
|
|
\/\\///\\\//\/\\///\\\//\/\\///\\\//\/
|
|
|
|
\/\\//\/ \/\\//\/ \/\\//\/
|
|
|
|
\/ \/ \/
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
The **-a** *format* option can be used to position the input text inside a box which is larger than needed for our text.
|
|
|
|
`hcvc` stands for "<STRONG>h</STRONG>orizontally <STRONG>c</STRONG>entered, <STRONG>v</STRONG>ertically
|
|
|
|
<STRONG>c</STRONG>entered".
|
2015-05-12 21:50:01 +02:00
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Note that the box was drawn in this size because the shapes that compose it are very big, so that it is not possible to
|
|
|
|
fit the box tighter around our text. Note also that the input lines themselves are *not* centered; `hc` only centers
|
|
|
|
the input text block as a whole.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2
|
|
|
|
text="Line justification" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d simple -a jr`
|
|
|
|
|
|
|
|
************************
|
|
|
|
*Different all twisty a*
|
|
|
|
* of in maze are you,*
|
|
|
|
* passages little.*
|
|
|
|
************************
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
This uses the third possible argument to the **-a** option, `j`. `jr` stands for "<STRONG>j</STRONG>ustification
|
|
|
|
<STRONG>r</STRONG>ight".
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2
|
|
|
|
text="Quick alignment/positioning" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d dog -a c`
|
|
|
|
|
|
|
|
__ _,--="=--,_ __
|
|
|
|
/ \." .-. "./ \
|
|
|
|
/ ,/ _ : : _ \/` \
|
|
|
|
\ `| /o\ :_: /o\ |\__/
|
|
|
|
`-'| :="~` _ `~"=: |
|
|
|
|
\` (_) `/
|
|
|
|
.-"-. \ | / .-"-.
|
|
|
|
.---{ }--| /,.-'-.,\ |--{ }---.
|
|
|
|
) (_)_)_) \_/`~-===-~`\_/ (_(_(_) (
|
|
|
|
( Different all twisty a )
|
|
|
|
) of in maze are you, (
|
|
|
|
( passages little. )
|
|
|
|
) (
|
|
|
|
'---------------------------------------'
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Since noone really wants to type `-a hcvcjc` only to actually center text inside a box, there are shorthand notations
|
|
|
|
(`l`, `c`, and `r`).
|
2015-05-12 21:50:01 +02:00
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Note the blank line at the bottom of the box (after `little`, but before the dashes) which is necessary to make the
|
|
|
|
bottom of the box look right. If the blank line was not there, the box would end on a closing parenthesis, thus looking
|
|
|
|
broken.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="size"
|
|
|
|
text="Box size specification" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d html -s 40`
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
<!-- - - - - - - - - - - - - - - - - -->
|
2015-05-12 21:50:01 +02:00
|
|
|
<!-- Different all twisty a -->
|
|
|
|
<!-- of in maze are you, -->
|
|
|
|
<!-- passages little. -->
|
2021-05-26 21:13:21 +02:00
|
|
|
<!-- - - - - - - - - - - - - - - - - -->
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
Using `-s 40`, we have set the box width to 40 characters.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="size2"
|
|
|
|
text="Box size specification (2)" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d peek -a c -s 40x11`
|
|
|
|
|
|
|
|
/* _\|/_
|
|
|
|
(o o)
|
|
|
|
+----oOO-{_}-OOo----------------------+
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| Different all twisty a |
|
|
|
|
| of in maze are you, |
|
|
|
|
| passages little. |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
+------------------------------------*/
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Using `-s 40x11`, you can set both width and height. Setting just the height is possible with `-s x11` (note the
|
|
|
|
leading `x` on the argument).
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="padding"
|
|
|
|
text="Text Padding" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d shell -p a1l2`
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# #
|
|
|
|
# Different all twisty a #
|
|
|
|
# of in maze are you, #
|
|
|
|
# passages little. #
|
|
|
|
# #
|
|
|
|
###########################
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Normally, the padding values depend on the design. The "shell" design has no default padding, so we can see
|
|
|
|
the effects of our command line option unchanged. `a1l2` stands for "<STRONG>a</STRONG>ll <STRONG>1</STRONG>,
|
|
|
|
<STRONG>l</STRONG>eft <STRONG>2</STRONG>", and tells *boxes* to put one space (or empty line, in the vertical
|
|
|
|
direction) around the input text block, except for the left side where two spaces shall be used.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="padding2"
|
|
|
|
text="Text Padding (2)" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -p h0v0`
|
|
|
|
|
|
|
|
/************************/
|
|
|
|
/*Different all twisty a*/
|
|
|
|
/*of in maze are you, */
|
|
|
|
/*passages little. */
|
|
|
|
/************************/
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
This uses again the default design, which by default features a horizontal padding value of one space (as you know from
|
|
|
|
the very first example). By specifying `-p h0v0`, we set all padding to zero ("<STRONG>h</STRONG>orizontal
|
|
|
|
<STRONG>0</STRONG>, <STRONG>v</STRONG>ertical <STRONG>0</STRONG>"). In this case, the same could have been
|
|
|
|
achieved by `-p h0` or `-p a0`.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="comments"
|
|
|
|
text="Regional comments" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
Imagine you want to comment out the following C code:
|
|
|
|
|
|
|
|
if (!s2 || *s2 == '\0')
|
|
|
|
return (char *) s1; /* error 1 */
|
|
|
|
if (!s1 || *s1 == '\0')
|
|
|
|
return NULL; /* error 2 */
|
|
|
|
if (skip < 0)
|
|
|
|
skip = 0; /* foo bar */
|
|
|
|
|
|
|
|
`boxes -d c-cmt`
|
|
|
|
|
|
|
|
/* if (!s2 || *s2 == '\0') */
|
|
|
|
/* return (char *) s1; /* error 1 *\/ */
|
|
|
|
/* if (!s1 || *s1 == '\0') */
|
|
|
|
/* return NULL; /* error 2 *\/ */
|
|
|
|
/* if (skip < 0) */
|
|
|
|
/* skip = 0; /* foo bar *\/ */
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Note that the closing comment tags in the input text have been escaped by adding a backslash between the asterisk and
|
|
|
|
the slash. This way, the comments that have been commented out along with the rest of the code will not interfere with
|
|
|
|
the new comments.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -r`
|
|
|
|
|
|
|
|
if (!s2 || *s2 == '\0')
|
|
|
|
return (char *) s1; /* error 1 */
|
|
|
|
if (!s1 || *s1 == '\0')
|
|
|
|
return NULL; /* error 2 */
|
|
|
|
if (skip < 0)
|
|
|
|
skip = 0; /* foo bar */
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Should you decide to reactivate the code previouly commented out, the escaped closing comment tags are changed back
|
|
|
|
into normal ones. This is achieved by the `replace` and `reverse` statements in the config file entry describing this
|
|
|
|
particular box design. If you want this to work recursively, simply add more such statements.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="removal"
|
|
|
|
text="Box removal" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Imagine your once beautiful box in "C" style like this in your editor, after you are done editing the text
|
|
|
|
inside:
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/* Generate sorted listing of available box styles.
|
|
|
|
Uses design name from BOX spec and sample picture plus author.
|
|
|
|
*/
|
|
|
|
/* RETURNS: != 0 on error (out of memory) */
|
|
|
|
== 0 on success */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
`boxes -r`
|
|
|
|
|
|
|
|
Generate sorted listing of available box styles.
|
|
|
|
Uses design name from BOX spec and sample picture plus author.
|
|
|
|
|
|
|
|
RETURNS: != 0 on error (out of memory)
|
|
|
|
== 0 on success
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
The box is correctly removed even though it's been badly damaged by editing of the text inside. Obviously, the box
|
|
|
|
design was correctly autodected as being "C". Note there is only a single leading space in the output text,
|
|
|
|
whereas there are two leading spaces in the input text. This is because the "C" box design has a default
|
|
|
|
horizontal padding of one space. Since *boxes* assumes it has added the padding space, it also attempts to removes
|
|
|
|
the same number of spaces when removing the box. Thus, if you were to add a new box around the text, the box internal
|
|
|
|
indentation would be retained. It is easily possible to use this feature to make an editor key mapping which repairs
|
2021-05-26 21:29:28 +02:00
|
|
|
a box for you (see [installation]({{ site.baseurl}}/editors.html) in the documentation section).
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="removal2"
|
|
|
|
text="Box removal (2)" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
Imagine an HTML comment box like the follwing, and imagine that *boxes* does not correctly autodetect it as being an
|
|
|
|
HTML box:
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
<!-- - - - - - - - - - - - - -->
|
|
|
|
<!-- Different all twisty a -->
|
|
|
|
<!-- of in maze are you, -->
|
|
|
|
<!-- passages little. -->
|
|
|
|
<!-- - - - - - - - - - - - - -->
|
|
|
|
|
|
|
|
`boxes -r -d html`
|
|
|
|
|
|
|
|
Different all twisty a
|
|
|
|
of in maze are you,
|
|
|
|
passages little.
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
In cases where design autodetection fails, **-d** *design_name* can be added to the **-r** command in order to tell
|
|
|
|
*boxes* which design exactly to remove. It is always a good thing to use the **-d** option, because it makes
|
|
|
|
autodetection unnecessary. Autodetection takes more time, because the entire config file must be parsed instead of just
|
|
|
|
the one design needed, and all designs must be matched against the input text in order to see which one fits best.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="indent"
|
|
|
|
text="Indentation handling" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
For this example, our input text is indented by four spaces:
|
|
|
|
|
|
|
|
Different all twisty a
|
|
|
|
of in maze are you,
|
|
|
|
passages little.
|
|
|
|
|
|
|
|
`boxes -d java-cmt -i box`
|
|
|
|
|
|
|
|
// Different all twisty a
|
|
|
|
// of in maze are you,
|
|
|
|
// passages little.
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
The default indent mode is `box`, which indents the box by the same value as the input text was indented. As shown
|
|
|
|
here, this is useful when adding regional comments to your source code, e.g. when "commenting out" a large
|
|
|
|
portion of your code. Most people generally prefer to indent comments by the same value as the code they refer to, so
|
|
|
|
they don't upset the code structure.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d vim-cmt -i text`
|
|
|
|
|
|
|
|
" Different all twisty a
|
|
|
|
" of in maze are you,
|
|
|
|
" passages little.
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
By specifying `-i text`, the box is made to start at column zero and any input text indentation is retained inside the
|
|
|
|
box.
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d pound-cmt -i none`
|
|
|
|
|
|
|
|
# Different all twisty a
|
|
|
|
# of in maze are you,
|
|
|
|
# passages little.
|
|
|
|
|
|
|
|
Finally, it is also possible to throw away any indentation altogether by specifying `-i none`.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2 slug="regexp"
|
|
|
|
text="Use of Regular Expressions" %}
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
Global Variables
|
|
|
|
|
|
|
|
`boxes -d headline`
|
|
|
|
|
|
|
|
/*************************************/
|
|
|
|
/* G l o b a l V a r i a b l e s */
|
|
|
|
/*************************************/
|
|
|
|
|
2021-02-17 20:58:16 +01:00
|
|
|
The `replace` and `reverse` statements may contain regular expressions and backreferences, which can be used for more
|
|
|
|
elaborate text modifications. The example shown here, where spaces are inserted between the individual characters, is
|
2021-05-26 21:13:21 +02:00
|
|
|
configured [like
|
|
|
|
this](https://github.com/{{ site.github }}/blob/ac8617b3839d372e108b6eea3a5e7743232281da/boxes-config#L1734-L1739).
|
2015-05-12 21:50:01 +02:00
|
|
|
|
|
|
|
`boxes -d headline -r`
|
|
|
|
|
|
|
|
Global Variables
|