class Object
Constants
- BG
- BLINK
- BOLD
- COLORS
functions to apply colors to terminal output
- FG
- NEUTRAL
- RD
/***************************************************************************
* ©2011-2019, Michael Uplawski <michael.uplawski@uplawski.eu> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/
- REGULAR
- STYLES
- SUMMARY
- SWAP
- UNDERLINE
- VERSION
/***************************************************************************
* ©2019-2019 Michael Uplawski <michael.uplawski@uplawski.eu> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/
Public Instance Methods
black(text)
click to toggle source
# File lib/color_output.rb, line 37 def black(text); colorize(text, "\033[30m"); end
black_on_white(text)
click to toggle source
# File lib/color_output.rb, line 39 def black_on_white(text); colorize(colorize(text, "\033[30m"), "\033[47m");end
blue(text)
click to toggle source
# File lib/color_output.rb, line 35 def blue(text); colorize(text, "\033[34m"); end
bold(text)
click to toggle source
# File lib/color_output.rb, line 42 def bold(text); style(text, "\033[01m");end
colored_output(output_text, fg_color = :default, bg_color = :default, style = :regular , mode = :neutral )
click to toggle source
# File lib/color_output.rb, line 26 def colored_output(output_text, fg_color = :default, bg_color = :default, style = :regular , mode = :neutral ) "\033[%i;%i;%i%i;%i%im%s\033[0m" %[STYLES[mode.to_sym], STYLES[style.to_sym], FG, COLORS[fg_color.to_sym], BG, COLORS[bg_color.to_sym], output_text] end
colorize(text, color_code)
click to toggle source
# File lib/color_output.rb, line 18 def colorize(text, color_code) "#{color_code}#{text}\033[0m" end
cyan(text)
click to toggle source
# File lib/color_output.rb, line 34 def cyan(text); colorize(text, "\033[36m"); end
green(text)
click to toggle source
# File lib/color_output.rb, line 31 def green(text); colorize(text, "\033[32m"); end
purple(text)
click to toggle source
# File lib/color_output.rb, line 33 def purple(text); colorize(text, "\033[35m"); end
red(text)
click to toggle source
# File lib/color_output.rb, line 30 def red(text); colorize(text, "\033[31m"); end
style(text, style_code)
click to toggle source
# File lib/color_output.rb, line 22 def style(text, style_code) "#{style_code}#{text}\033[0m" end
underline(text)
click to toggle source
# File lib/color_output.rb, line 43 def underline(text); style(text, "\033[04m");end
wait_for_user()
click to toggle source
The totally mystic and heard-about-so-long, fantastic and marvelous… Non-blocking User-Input. I have seen this somewhere and am explicitely thankful to someone to have written something about it.
# File lib/user_input.rb, line 34 def wait_for_user() char = nil STDIN.raw do STDIN.noecho do until (STDIN.ready?) sleep(0.1) end char = (STDIN.read_nonblock(1).ord rescue nil) end end return char end
white(text)
click to toggle source
# File lib/color_output.rb, line 36 def white(text); colorize(text, "\033[37m"); end
white_on_black(text)
click to toggle source
# File lib/color_output.rb, line 40 def white_on_black(text); colorize(colorize(text, "\033[37m"), "\033[40m");end
yellow(text)
click to toggle source
# File lib/color_output.rb, line 32 def yellow(text); colorize(text, "\033[33m"); end