Class: EverydayCurses::MyCurses
- Inherits:
-
Object
- Object
- EverydayCurses::MyCurses
show all
- Includes:
- CursesUtils
- Defined in:
- lib/everyday-curses/mycurses.rb
Constant Summary
Constants included
from CursesUtils
CursesUtils::COLOR_TO_CURSES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_color, #find_color
Constructor Details
#initialize(use_curses, linesh, linesf) ⇒ MyCurses
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/everyday-curses/mycurses.rb', line 8
def initialize(use_curses, linesh, linesf)
@use_curses = use_curses
@linesh = linesh
@linesf = linesf
@colors = []
= []
@bodies = []
= []
@cur_l = 0
@max_l = 0
@ch = nil
setup_curses(linesf, linesh) if @use_curses
end
|
Instance Attribute Details
#bodies ⇒ Object
Returns the value of attribute bodies.
195
196
197
|
# File 'lib/everyday-curses/mycurses.rb', line 195
def bodies
@bodies
end
|
#ch ⇒ Object
194
195
196
|
# File 'lib/everyday-curses/mycurses.rb', line 194
def ch
@ch
end
|
Returns the value of attribute footers.
195
196
197
|
# File 'lib/everyday-curses/mycurses.rb', line 195
def
end
|
Returns the value of attribute headers.
195
196
197
|
# File 'lib/everyday-curses/mycurses.rb', line 195
def
end
|
Instance Method Details
#body_live_append(str) ⇒ Object
113
114
115
116
|
# File 'lib/everyday-curses/mycurses.rb', line 113
def body_live_append(str)
@padb << str
padb_refresh
end
|
#clear ⇒ Object
48
49
50
51
52
|
# File 'lib/everyday-curses/mycurses.rb', line 48
def clear
= []
@bodies = []
= []
end
|
#clear_ch ⇒ Object
92
93
94
95
96
97
|
# File 'lib/everyday-curses/mycurses.rb', line 92
def clear_ch
read_ch
while @ch == 10 || @ch == Curses::Key::ENTER || @ch == Curses::Key::UP || @ch == Curses::Key::DOWN
read_ch
end
end
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/everyday-curses/mycurses.rb', line 33
def configure_curses
@padh.keypad(true)
@padh.clear
@padh.nodelay = true
@padb.keypad(true)
@padb.clear
@padb.nodelay = true
@padf.keypad(true)
@padf.clear
@padf.nodelay = true
Curses::cbreak
Curses::start_color
Curses::use_default_colors
end
|
#dispose ⇒ Object
123
124
125
|
# File 'lib/everyday-curses/mycurses.rb', line 123
def dispose
Curses::close_screen if @use_curses
end
|
118
119
120
121
|
# File 'lib/everyday-curses/mycurses.rb', line 118
def (str)
@padf << str
padf_refresh
end
|
108
109
110
111
|
# File 'lib/everyday-curses/mycurses.rb', line 108
def (str)
@padh << str
padh_refresh
end
|
#myprints ⇒ Object
54
55
56
|
# File 'lib/everyday-curses/mycurses.rb', line 54
def myprints
@use_curses ? print_curses : print_normal
end
|
#print_curses ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/everyday-curses/mycurses.rb', line 64
def print_curses
resize_curses
myprint(.join("\n"), @padh)
myprint(@bodies.join("\n"), @padb)
myprint(.join("\n"), @padf)
update_max_l
@cur_l = [@cur_l, @max_l].min
padh_refresh
padb_refresh
padf_refresh
end
|
#print_normal ⇒ Object
58
59
60
61
62
|
# File 'lib/everyday-curses/mycurses.rb', line 58
def print_normal
.each { |v| puts v }
@bodies.each { |v| puts v }
.each { |v| puts v }
end
|
#read_ch ⇒ Object
88
89
90
|
# File 'lib/everyday-curses/mycurses.rb', line 88
def read_ch
@ch = @padf.getch
end
|
#resize_curses ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/everyday-curses/mycurses.rb', line 76
def resize_curses
@padh.resize(.count, Curses::cols)
@padb.resize(@bodies.count, Curses::cols)
@padf.resize(.count, Curses::cols)
@padh.clear
@padb.clear
@padf.clear
@padh.setpos(0, 0)
@padb.setpos(0, 0)
@padf.setpos(0, 0)
end
|
99
100
101
102
103
104
105
106
|
# File 'lib/everyday-curses/mycurses.rb', line 99
def scroll_iteration
old_subpad_size = @subpad_size
update_subpad_size
update_max_l
update_scroll(@subpad_size != old_subpad_size)
sleep(0.05)
read_ch
end
|
#setup_curses(linesf, linesh) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/everyday-curses/mycurses.rb', line 22
def setup_curses(linesf, linesh)
Curses::noecho
Curses::init_screen
@subpad_start = linesh
update_subpad_size
@padh = Curses::Pad.new(linesh, Curses::cols)
@padb = Curses::Pad.new(Curses::lines - linesh - linesf, Curses::cols)
@padf = Curses::Pad.new(linesf, Curses::cols)
configure_curses
end
|