网站搜索

Boxes - 在 Linux 终端中绘制 ASCII 艺术框和形状


Boxes 是一个简单的、可配置的命令行程序,它可以在其输入文本周围绘制任何类型的框。它过滤文本并在其周围绘制形状——它实际上是一个文本过滤器。事实上,它被设计为作为文本过滤器与您的编辑器集成(默认支持 Vim)。它可以绘制从简单的盒子到复杂的 ASCII 艺术的各种形状。

在本文中,我们将学习如何使用 box 实用程序在 Linux 终端中绘制形状。

如何在 Linux 中安装 Boxes 实用程序

要在 Linux 中安装 boxes 实用程序,请使用适合您的发行版的命令。

sudo apt install boxes  [On Debian/Ubuntu]
sudo yum install boxes  [On CentOS/RHEL]
sudo dnf install boxes  [On Fedora]

现在您已经安装了 Box,请注意,它使用 $HOME/.boxes 用户特定配置文件或 /etc/boxes/boxes-config 系统范围配置文件。

让我们享受 Linux 终端的乐趣吧。

要查看默认框设计,只需向其提供一些输入文本,如图所示。

$ echo "Hey, this is linux-console.net! Thanks for following us." | boxes

/******************************************************/
/* Hey, this is linux-console.net! Thanks for following us. */
/******************************************************/

要指定其他设计,请使用 -d 标志,如图所示。

$ echo "Hey, this is linux-console.net! Thanks for following us." | boxes -d boy

                        .-"""-.
                       / .===. \
                       \/ 6 6 \/
                       ( \___/ )
  _________________ooo__\_____/_____________________
 /                                                  \
| Hey, this is linux-console.net! Thanks for following us. |
 \______________________________ooo_________________/
                       |  |  |
                       |_ | _|
                       |  |  |
                       |__|__|
                       /-'Y'-\
                      (__/ \__)

要对齐或定位框中的文本,请使用 -a 标志。让我们通过以下示例演示它是如何工作的(其中 c 表示中心)。

$ echo "Hey, this is linux-console.net! Thanks for following us." | boxes -d diamonds

       /\          /\          /\          /\          /\
    /\//\\/\    /\//\\/\    /\//\\/\    /\//\\/\    /\//\\/\
 /\//"///\\/\//"///\\/\//"///\\/\//"///\\/\//"///\\/\
//"//\/\\///"//\/\\///"//\/\\///"//\/\\///"//\/\\///\\
\\//\/Hey, this is linux-console.net! Thanks for following us.  \/\\//
 \/                                                          \/
 /\                                                          /\
//\\                                                        //\\
\\//                                                        \\//
 \/                                                          \/
 /\                                                          /\
//\\/\                                                    /\//\\
\\///\\/\//"///\\/\//"///\\/\//"///\\/\//"///\\/\//"//
 \/\\///"//\/\\///"//\/\\///"//\/\\///"//\/\\///"//\/
    \/\\//\/    \/\\//\/    \/\\//\/    \/\\//\/    \/\\//\/
       \/          \/          \/          \/          \/
$ echo "Hey, this is linux-console.net! Thanks for following us." | boxes -d diamonds -a c

       /\          /\          /\          /\          /\
    /\//\\/\    /\//\\/\    /\//\\/\    /\//\\/\    /\//\\/\
 /\//"///\\/\//"///\\/\//"///\\/\//"///\\/\//"///\\/\
//"//\/\\///"//\/\\///"//\/\\///"//\/\\///"//\/\\///\\
\\//\/                                                    \/\\//
 \/                                                          \/
 /\                                                          /\
//\\   Hey, this is linux-console.net! Thanks for following us.   //\\
\\//                                                        \\//
 \/                                                          \/
 /\                                                          /\
//\\/\                                                    /\//\\
\\///\\/\//"///\\/\//"///\\/\//"///\\/\//"///\\/\//"//
 \/\\///"//\/\\///"//\/\\///"//\/\\///"//\/\\///"//\/
    \/\\//\/    \/\\//\/    \/\\//\/    \/\\//\/    \/\\//\/
       \/          \/          \/          \/          \/

例如,在圣诞节期间,您可以使用圣诞老人设计向家人和朋友发送节日快乐信息。

$ echo "linux-console.net wishes you a Merry Christmas and a Happy New Year 2019" | boxes -d santa

                                 .-"``"-.
                                /______; \
                               {_______}\|
                               (/ a a \)(_)
                               (.-.).-.)
  _______________________ooo__(    ^    )___________________________
 /                             '-.___.-'                            \
| linux-console.net wishes you a Merry Christmas and a Happy New Year 2019 |
 \________________________________________ooo_______________________/
                               |_  |  _|  jgs
                               \___|___/
                               {___|___}
                                |_ | _|
                                /-'Y'-\
                               (__/ \__)

要列出所有可用的设计/样式,请运行以下命令。

$ boxes -l

59 Available Styles in "/etc/boxes/boxes-config":
-------------------------------------------------

ada-box
(public domain), coded by Neil Bird <[email >:

    ---------------
    --           --
    --           --
    ---------------


ada-cmt
(public domain), coded by Neil Bird <[email >:

    --
    -- regular Ada
    -- comments
...

它支持行对齐、框大小规范、文本填充、缩进、正则表达式的使用等等。

情人节即将来临,您想以 Linux 的方式给您的女朋友或妻子留下深刻的印象,那么请使用如图所示的盒子。

$ echo -e "\n\tMe: Will you be my Valentine?\n\tGirl: No way\n\tMe: sudo will you be my Valentine?\n\tGirl: Yes..yes..yes! Let's go!" | boxes -d boy

                        .-"""-.
                       / .===. \
                       \/ 6 6 \/
                       ( \___/ )
          _________ooo__\_____/_____________
         /                                  \
        |                                    |
        | Me: Will you be my Valentine?      |
        | Girl: No way                       |
        | Me: sudo will you be my Valentine? |
        | Girl: Yes..yes..yes! Let's go!     |
         \______________________ooo_________/
                       |  |  |
                       |_ | _|
                       |  |  |
                       |__|__|
                       /-'Y'-\
                      (__/ \__)

有关更多信息和示例,请访问 http://boxes.thomasjensen.com/examples.html。

Boxes 是一个命令行实用程序,可在其输入文本周围绘制一个框。在本文中,我们将学习如何安装和使用 box 实用程序在 Linux 终端中绘制形状。使用下面的反馈表来分享您的想法。