Class: Daigaku::Window
- Inherits:
-
Curses::Window
- Object
- Curses::Window
- Daigaku::Window
show all
- Includes:
- Coloring
- Defined in:
- lib/daigaku/window.rb
Constant Summary
Constants included
from Coloring
Coloring::BACKGROUND, Coloring::COLOR_GREEN, Coloring::COLOR_HEADING, Coloring::COLOR_RED, Coloring::COLOR_TEXT, Coloring::COLOR_TEXT_EMPHASIZE, Coloring::COLOR_YELLOW, Coloring::FONT, Coloring::FONT_EMPHASIZE, Coloring::FONT_HEADING, Coloring::GREEN, Coloring::RED, Coloring::YELLOW
Instance Method Summary
collapse
-
#clear_line(options = {}) ⇒ Object
clear_line(options = {}) options: [:color, :text_decoration, :start_pos, :end_pos, :text].
-
#colored(text, color, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
-
#emphasize(text, text_decoration = Curses::A_NORMAL) ⇒ Object
-
#green(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
-
#heading(text, text_decoration = Curses::A_UNDERLINE) ⇒ Object
-
#initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0) ⇒ Window
constructor
A new instance of Window.
-
#print_indicator(object, text = ' ', text_decoration = Curses::A_STANDOUT) ⇒ Object
-
#print_markdown(text) ⇒ Object
-
#red(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
-
#write(text, color = COLOR_TEXT, text_decoration = Curses::A_NORMAL) ⇒ Object
-
#yellow(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
Constructor Details
#initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0) ⇒ Window
Returns a new instance of Window.
9
10
11
12
|
# File 'lib/daigaku/window.rb', line 9
def initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0)
super(height, width, top, left)
init_colors
end
|
Instance Method Details
#clear_line(options = {}) ⇒ Object
clear_line(options = {}) options: [:color, :text_decoration, :start_pos, :end_pos, :text]
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/daigaku/window.rb', line 55
def clear_line(options = {})
color = options[:color] || COLOR_TEXT
text_decoration = options[:text_decoration] || Curses::A_NORMAL
start = options[:start_pos] || 0
stop = options[:end_pos] || maxx
x = curx
setpos(cury, start)
write((options[:text] || ' ') * (stop - 1), color, text_decoration)
setpos(cury, x)
refresh
end
|
#colored(text, color, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/daigaku/window.rb', line 38
def colored(text, color, text_decoration = Curses::A_NORMAL, options = {})
if options[:full_line]
clear_line(
color: color,
text_decoration: Curses::A_STANDOUT,
start_pos: 1,
end_pos: maxx - 2
)
prefix = ' '
end
write("#{prefix}#{text}", color, text_decoration)
end
|
#emphasize(text, text_decoration = Curses::A_NORMAL) ⇒ Object
18
19
20
|
# File 'lib/daigaku/window.rb', line 18
def emphasize(text, text_decoration = Curses::A_NORMAL)
write(text, COLOR_TEXT_EMPHASIZE, text_decoration)
end
|
#green(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
34
35
36
|
# File 'lib/daigaku/window.rb', line 34
def green(text, text_decoration = Curses::A_NORMAL, options = {})
colored(text, COLOR_GREEN, text_decoration, options)
end
|
#heading(text, text_decoration = Curses::A_UNDERLINE) ⇒ Object
22
23
24
|
# File 'lib/daigaku/window.rb', line 22
def heading(text, text_decoration = Curses::A_UNDERLINE)
write(text, COLOR_HEADING, text_decoration)
end
|
#print_indicator(object, text = ' ', text_decoration = Curses::A_STANDOUT) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/daigaku/window.rb', line 68
def print_indicator(object, text = ' ', text_decoration = Curses::A_STANDOUT)
if object.respond_to?(:mastered?) && object.respond_to?(:started?)
if object.mastered?
green(text, text_decoration)
elsif object.started?
yellow(text, text_decoration)
else
red(text, text_decoration)
end
elsif object.respond_to?(:mastered?)
if object.mastered?
green(text, text_decoration)
else
red(text, text_decoration)
end
end
write ' '
end
|
#print_markdown(text) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/daigaku/window.rb', line 88
def print_markdown(text)
clear_line
printer = Markdown::Printer.new(window: self)
printer.print(text)
end
|
#red(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
26
27
28
|
# File 'lib/daigaku/window.rb', line 26
def red(text, text_decoration = Curses::A_NORMAL, options = {})
colored(text, COLOR_RED, text_decoration, options)
end
|
#write(text, color = COLOR_TEXT, text_decoration = Curses::A_NORMAL) ⇒ Object
14
15
16
|
# File 'lib/daigaku/window.rb', line 14
def write(text, color = COLOR_TEXT, text_decoration = Curses::A_NORMAL)
attron(Curses.color_pair(color) | text_decoration) { self << text.to_s }
end
|
#yellow(text, text_decoration = Curses::A_NORMAL, options = {}) ⇒ Object
30
31
32
|
# File 'lib/daigaku/window.rb', line 30
def yellow(text, text_decoration = Curses::A_NORMAL, options = {})
colored(text, COLOR_YELLOW, text_decoration, options)
end
|