Module: ColorMap
- Included in:
- RubyCurses, VER
- Defined in:
- lib/rbcurse/colormap.rb
Class Method Summary collapse
- .colors ⇒ Object
-
.get_color(fgc, bgc = $def_bg_color) ⇒ Object
public returns a color_pair for a given foreground and background color.
-
.get_color_const(colorstring) ⇒ Object
private returns a color constant for a human color string.
-
.install_color(fgc, bgc) ⇒ Object
private creates a new color pair, puts in color map and returns color_pair number.
-
.setup ⇒ Object
public setup color map at start of application.
Class Method Details
.colors ⇒ Object
32 33 34 |
# File 'lib/rbcurse/colormap.rb', line 32 def ColorMap.colors @@colors end |
.get_color(fgc, bgc = $def_bg_color) ⇒ Object
public returns a color_pair for a given foreground and background color
23 24 25 26 27 28 29 30 31 |
# File 'lib/rbcurse/colormap.rb', line 23 def ColorMap.get_color fgc, bgc=$def_bg_color if $color_map.include? [fgc, bgc] # $log.debug " get_color found #{fgc} #{@bgc} " return $color_map[[fgc, bgc]] else # $log.debug " get_color NOT found #{fgc} #{@bgc} " return ColorMap.install_color fgc, bgc end end |
.get_color_const(colorstring) ⇒ Object
private returns a color constant for a human color string
6 7 8 |
# File 'lib/rbcurse/colormap.rb', line 6 def ColorMap.get_color_const colorstring Ncurses.const_get "COLOR_#{colorstring.upcase}" end |
.install_color(fgc, bgc) ⇒ Object
private creates a new color pair, puts in color map and returns color_pair number
12 13 14 15 16 17 18 19 20 |
# File 'lib/rbcurse/colormap.rb', line 12 def ColorMap.install_color fgc, bgc # $log.debug " install_color found #{fgc} #{@bgc} " @color_id += 1 fg = ColorMap.get_color_const fgc bg = ColorMap.get_color_const bgc Ncurses.init_pair(@color_id, fg, bg); $color_map[[fgc, bgc]] = @color_id return @color_id end |
.setup ⇒ Object
public setup color map at start of application
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rbcurse/colormap.rb', line 38 def ColorMap.setup @color_id = 0 $color_map = {} Ncurses.start_color(); # Initialize few color pairs $def_fg_color = "white" # pls set these 2 for your application $def_bg_color = "black" #COLORS = [COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, # COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE] @@colors = %w[black red green yellow blue magenta cyan white] # make foreground colors bg = ColorMap.get_color_const $def_bg_color @@colors[0...@@colors.size].each_with_index do |color, i| next if color == $def_bg_color ColorMap.install_color color, $def_bg_color end $reversecolor = ColorMap.get_color $def_bg_color, $def_fg_color $popupcolor = ColorMap.get_color 'cyan', $def_fg_color $errorcolor = ColorMap.get_color 'white', 'red' $promptcolor = $selectedcolor = ColorMap.get_color('yellow', 'red') $normalcolor = $datacolor = ColorMap.get_color('white', 'black') $bottomcolor = $topcolor = ColorMap.get_color('white', 'blue') # $log.debug " colormap SETUP: #{$datacolor} #{$reversecolor} " end |