使用 lolcat 为你的 Linux 终端带来彩虹
颜色 彩虹

> 
> 使用这个简单的工具，你可以为所需的任何程序的输出变成七彩。
> 
> 
> 


![](/data/attachment/album/201812/18/160350ezquzucc15yuw4ru.png)


今天是 Linux 命令行玩具日历的第五天。如果这是你第一次访问该系列，你可能会问自己，什么是命令行玩具。即使我不太确定，但一般来说，它可能是一个游戏，或任何简单的可以帮助你在终端玩得开心的东西。


很可能你们中的一些人之前已经看过我们日历中的各种玩具，但我们希望每个人至少见到一件新事物。


今日的选择，`lolcat`，是我选择的第一个没有在我的 Linux 发行版中打包的程序，但它安装仍然很简单。它是一个 Ruby 程序，你应该可以使用下面的命令轻松地添加到系统中。



```
$ gem install lolcat
```

之后，只需将一些文本传送给它，就可以看到彩色的输出。例如，尝试几个之前在我们的日历中出现的程序，使用以下命令：



```
$ fortune | boxes -a c -d parchment | lolcat
```

根据你的运气，你可能会看到这样：


![](/data/attachment/album/201812/18/160350fdf1n3v1nst6mvlx.png)


你可以传递给 `lolcat` 一些参数。这里不再赘述，我建议你访问 `lolcat` 的 [GitHub 页面](https://github.com/busyloop/lolcat) 或者在终端输入 `lolcat --help` 了解。但一般来说，它们能设置彩虹的传递和频率，以及我个人最喜欢的动画。谁不喜欢终端的彩色动画输出呢？让我们再试一次，用一个不同的边框（当然是以猫为主题）和一句在我的格言列表中的适合猫的句子。



```
fortune -m "nine tails" | boxes -a c -d cat | lolcat -a
```

![](/data/attachment/album/201812/18/160353xncgcr2smwbvjzre.gif)


`lolcat` 是一个 BSD 许可下的开源软件。


你有特别喜欢的命令行小玩具需要我介绍的吗？这个系列要介绍的小玩具大部分已经有了落实，但还预留了几个空位置。如果你有特别想了解的可以评论留言，我会查看的。如果还有空位置，我会考虑介绍它的。如果没有，但如果我得到了一些很好的意见，我会在最后做一些有价值的提及。


了解一下昨天的玩具，[在 Linux 命令行中拥有一头牛](https://opensource.com/article/18/12/linux-toy-cowsay)，还有记得明天再来！




---


via: <https://opensource.com/article/18/12/linux-toy-lolcat>


作者：[Jason Baker](https://opensource.com/users/jason-baker) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Today marks the fifth day of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, what’s a command-line toy. Even I'm not quite sure, but generally, it could be a game, or any simple diversion that helps you have fun at the terminal.

It's quite possible that some of you will have seen various selections from our calendar before, but we hope there’s at least one new thing for everyone.

Today's selection, **lolcat**, is the first utility I'm including that wasn't packaged for my Linux distribution, but it was still an easy install. It's a Ruby program that you ought to be able to easily add to your system with the following.

`$ gem install lolcat`


After that, simply pipe some text to it to see the output in the colors of the rainbow. For example, using a couple of utilities from earlier days in our advent calendar, try the following:

`$ fortune | boxes -a c -d parchment | lolcat`


Depending on what good fortune you have, you'll likely get something like this:

![A fortune displayed on the terminal A fortune displayed on the terminal](https://opensource.com/sites/default/files/uploads/linux-toy-lolcat-parchment.png)

There are a few parameters you can pass to **lolcat**, and rather than repeat them all here, I'd suggest you either visit the** lolcat **[GitHub page](https://github.com/busyloop/lolcat) or just see them at the terminal by typing **lolcat --help**. But generally, they're helpful to set the spread and frequency of your rainbow, and my personal favorite, enabling animation. Who doesn't like animated rainbow printing at the terminal? Let's try the above again, with a different box (cat-themed, of course) and a cat-appropriate fortune that was in my fortunes list, with the following.

`fortune -m "nine tails" | boxes -a c -d cat | lolcat -a`



![Animated lolcat Animated lolcat](https://opensource.com/sites/default/files/uploads/linux-toy-lolcat-animated.gif)

**lolcat** is open source under a BSD license.

Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.

Check out yesterday's toy, [Have a cow at the Linux command line](https://opensource.com/article/18/12/linux-toy-cowsay), and check back tomorrow for another!

## Comments are closed.