Change Font dynamically in console

醉酒当歌 提交于 2019-12-10 20:36:34

问题


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.

Is there anything in Ruby or some terminal commands to do so (I use Mac OS X).


回答1:


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

Examples:

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

Here is the colorize README.

Or if you'd like to get fancier and do some UI elements, you can use the rbcurse gem:

gem install rbcurse

Here are some rbcurse screenshots.




回答2:


I suggest you can use fancy_irb modules, which can decorate your irb console. :)

gem install fancy_irb




回答3:


There is no way to dynamically change the font face or font size in standard terminals. They mostly only recognise the standard ANSI/VT escape codes, which only support colors and (some) style.




回答4:


If you are looking for a solution for the rails default webconsole (displayed inside a browser) I suggest to get a browserextension where you can add additional styling to a page and then just override the following classes:

.console-prompt-label,
.console-prompt-display, 
.console-message {
  font-size: 16px;
  line-height: 16px;
}

If you're using chrome you can use StyleBot. Then you would need to:

  1. Install Stylebot
  2. run rails server and open localhost inside your browser
  3. click on the stylebot extension logo (CSS) and click Open Stylebot...
  4. a sidenav should open, at the bottom left press the button Edit CSS
  5. add the CSS from above and save

that's it, no more small console ouput ever.



来源:https://stackoverflow.com/questions/10053836/change-font-dynamically-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!