Class: BaseScreen
- Inherits:
-
Object
- Object
- BaseScreen
- Includes:
- Singleton
- Defined in:
- lib/term_canvas/base_screen.rb
Instance Method Summary collapse
- #find_or_create_color_pair(foreground_color: nil, background_color:) ⇒ Object
-
#initialize ⇒ BaseScreen
constructor
A new instance of BaseScreen.
Constructor Details
#initialize ⇒ BaseScreen
Returns a new instance of BaseScreen.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/term_canvas/base_screen.rb', line 6 def initialize Curses.init_screen Curses::noecho Curses.curs_set(0) Curses.stdscr.nodelay = 1 Curses.start_color Curses.use_default_colors @color_struct = Struct.new(:id, :r, :g, :b) @color_pair_struct = Struct.new(:id, :fc_id, :bc_id) @color_pairs = [@color_pair_struct.new(0, 1, 0)] @colors = [@color_struct.new(0, 0, 0, 0)] @color_id_offset = 16 end |
Instance Method Details
#find_or_create_color_pair(foreground_color: nil, background_color:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/term_canvas/base_screen.rb', line 28 def find_or_create_color_pair(foreground_color: nil, background_color:) response_color_pair = nil fc_id = find_or_create_color( @color_struct.new(*foreground_color&.values_at(*@color_struct.members)) ).id bc_id = find_or_create_color( @color_struct.new(*background_color&.values_at(*@color_struct.members)) ).id @color_pairs.each do |cp| if cp.fc_id == fc_id && cp.bc_id == bc_id response_color_pair = cp break end end return response_color_pair || create_color_pair(fc_id, bc_id) end |