在控制台中动态更改字体 [英] Change Font dynamically in console
问题描述
是否有适当的插件或类可以在常用输出控制台中更改字体大小,字体类型和装饰?
Is there a proper plugin or a class to change font size, font type and decoration within a common output console?
您可以通过进入偏好设置更改终端的字体但这不是我在这里寻找。我希望能够在代码内动态更改字体。
You can change terminal's font by going into preferences but that is not what I'm looking for here. I want to be able to change font dynamically from within code.
在Ruby或一些终端命令中有任何东西(我使用Mac OS X)。 p>
Is there anything in Ruby or some terminal commands to do so (I use Mac OS X).
推荐答案
ANSI终端中使用的字体/字体大小是实现特定的,ANSI颜色/样式代码是提供装饰的唯一方法。我发现添加颜色和风格到控制台输出的最简单的方法是使用 colorize
gem。
The font/font size used in ANSI terminals are implementation specific, and ANSI color/style codes are the only way to provide decoration. Simplest way I've found to add color and style to console output is use the colorize
gem.
gem install colorize
示例:
puts "This is blue".colorize( :blue )
puts "This is light blue".colorize( :light_blue )
puts "This is also blue".colorize( :color => :blue )
puts "This is red on blue and underline".colorize( :red ).on_blue.underline
puts "This is blue text on red".blue.on_red.blink
这是 colorize README 。
或者如果你想获得fancier并做一些UI元素,你可以使用 rbcurse
gem:
Or if you'd like to get fancier and do some UI elements, you can use the rbcurse
gem:
gem install rbcurse
以下是一些 rbcurse屏幕截图。
这篇关于在控制台中动态更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!