Class: Window

Inherits:
Object
  • Object
show all
Defined in:
lib/multish.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height, width, top, left) ⇒ Window

Returns a new instance of Window.



12
13
14
15
16
17
# File 'lib/multish.rb', line 12

def initialize(height, width, top, left)
  @window = Curses::Window.new(height, width, top, left)
  @fgcolor = :black
  @bgcolor = :bright_white
  reset!
end

Class Method Details

.create_color(code, r, g, b) ⇒ Object



79
80
81
82
83
84
# File 'lib/multish.rb', line 79

def self.create_color(code, r, g, b)
  @colors ||= {}
  new_index = 15 + @colors.count
  @colors[code] ||= [new_index, Curses.init_color(new_index, r, g, b)]
  @colors[code][0]
end

.create_color_pair(fg, bg) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/multish.rb', line 86

def self.create_color_pair(fg, bg)
  index = "#{fg}/#{bg}"
  @pairs ||= {}
  new_index = 100 + @pairs.count
  @pairs[index] ||= [new_index, Curses.init_pair(new_index, fg, bg)]
  @pairs[index][0]
end

.screen_heightObject



23
24
25
# File 'lib/multish.rb', line 23

def self.screen_height
  Curses.lines
end

.screen_widthObject



19
20
21
# File 'lib/multish.rb', line 19

def self.screen_width
  Curses.cols
end

Instance Method Details

#<<(str) ⇒ Object



94
95
96
# File 'lib/multish.rb', line 94

def <<(str)
  @window.addstr(str)
end

#bgcolor=(value) ⇒ Object



44
45
46
47
# File 'lib/multish.rb', line 44

def bgcolor=(value)
  @bgcolor = value
  update_color!
end

#bold=(value) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/multish.rb', line 31

def bold=(value)
  if value
    @window.attron(Curses::A_BOLD)
  else
    @window.attroff(Curses::A_BOLD)
  end
end

#fgcolor=(value) ⇒ Object



39
40
41
42
# File 'lib/multish.rb', line 39

def fgcolor=(value)
  @fgcolor = value
  update_color!
end

#get_code(color) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/multish.rb', line 56

def get_code(color)
  case color
  when :black
    Curses::COLOR_BLACK
  when :red
    Curses::COLOR_RED
  when :green
    Curses::COLOR_GREEN
  when :yellow
    Curses::COLOR_YELLOW
  when :blue
    Curses::COLOR_BLUE
  when :magenta
    Curses::COLOR_MAGENTA
  when :cyan
    Curses::COLOR_CYAN
  when :white
    Curses::COLOR_WHITE
  when :bright_white
    Window.create_color(:bright_white, 1000, 1000, 1000)
  end
end

#refresh!Object



102
103
104
# File 'lib/multish.rb', line 102

def refresh!
  @window.refresh
end

#reset!Object



106
107
108
109
110
# File 'lib/multish.rb', line 106

def reset!
  self.fgcolor = :black
  self.bgcolor = :bright_white
  self.bold = false
end

#scrollok(value) ⇒ Object



98
99
100
# File 'lib/multish.rb', line 98

def scrollok(value)
  @window.scrollok(value)
end

#setpos(x, y) ⇒ Object



27
28
29
# File 'lib/multish.rb', line 27

def setpos(x, y)
  @window.setpos(x, y)
end

#update_color!Object



49
50
51
52
53
54
# File 'lib/multish.rb', line 49

def update_color!
  fgcode = get_code(@fgcolor)
  bgcode = get_code(@bgcolor)
  code = Window.create_color_pair(fgcode, bgcode)
  @window.attron(Curses.color_pair(code))
end