如何使用Ruby对输出到终端的文本进行着色? [英] How can I use Ruby to colorize the text output to a terminal?

查看:52
本文介绍了如何使用Ruby对输出到终端的文本进行着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Ruby,如何在终端中对输出的背景和前景文本进行着色?

Using Ruby, how can I perform background and foreground text colorization for output in the terminal?

我记得,在对Pascal进行编程时,我们都曾经编写过自己的 textcolor(…)过程,以使我们的小型教育程序看起来更美观,更具表现力.

I remember, when programming Pascal we all used to write our own textcolor(…) procedures to make our small educational programs look more pretty and presentational.

我将如何在Ruby中编写与之等效的代码?核心库中是否有任何内置支持可用于此目的?如果没有,添加它的惯用方式是什么?

How would I go about coding an equivalent of that in Ruby? Is there any built-in support in the core library that lends itself to this? If not, what would be an idiomatic way to add it?

推荐答案

着色是我最喜欢的宝石!:-)

Colorize is my favorite gem! :-)

签出:

https://github.com/fazibear/colorize

安装:

gem install colorize

用法:

require 'colorize'

puts "I am now red".red
puts "I am now blue".blue
puts "Testing".yellow

这篇关于如何使用Ruby对输出到终端的文本进行着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆