如何在bash中创建基于文本的简单图形? [英] How can I create simple text-based graphics in bash?
问题描述
示例:
是否可以创建这样的线条和图像所示的两个小东西?如果是这样,我该怎么办?
Is it possible to create such lines and the two little things as the image shows? If so, how can I do this?
推荐答案
查看 http://en.wikipedia.org/wiki/Box-drawing_character
如果您的用户支持支持Unicode的终端,则可以执行以下操作:
If your user supports a Unicode-aware terminal, then, you could do something like:
printf '\u2500\u252c\u2500\nf%sO%so\n\u2500\u2534\u2500\n' \
"$(tput setf red)" "$(tput setf black)"
将 \ u2500
替换为水平条,将 \ u252c
替换为带有向下的三通的水平条,将 \ u2534
带有一个向上的三通的单杠等等.
The \u2500
s get replaced with horizontal bars, the \u252c
with a horizontal bar with a tee pointing down, the \u2534
with a horizontal bar with a tee pointing up, etc.
将%s
s替换为相应的参数-"$(tput setf red)"
,以使前景文本变为红色(或者,如果没有字符,当前的终端不支持彩色),"$(tput setf black)"
...好吧,明显的事情.
The %s
s get replaced with corresponding arguments -- "$(tput setf red)"
to make the foreground text red (or no character at all, if the current terminal doesn't support color), the "$(tput setf black)"
... well, does the obvious thing.
这篇关于如何在bash中创建基于文本的简单图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!