Class: Tiqbi::ViewController
- Inherits:
-
Object
- Object
- Tiqbi::ViewController
show all
- Includes:
- Utils
- Defined in:
- lib/tiqbi/view_controller.rb
Constant Summary
collapse
- MAIN_VIEW =
1
- DETAIL_VIEW =
2
- COMMAND_VIEW =
3
Constants included
from Utils
Utils::ENTITY_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#format_str, #split_str_with_width, #unescape_entity
Constructor Details
Returns a new instance of ViewController.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/tiqbi/view_controller.rb', line 17
def initialize(c_scr)
scr_x = c_scr.maxx - c_scr.begx
scr_y = c_scr.maxy - c_scr.begy
main_h = scr_y / 2
cmd_h = 1
detail_h = main_h - cmd_h
@views = {
MAIN_VIEW => View::MainView.new(c_scr, main_h, scr_x, 0, 0),
DETAIL_VIEW => View::DetailView.new(c_scr, detail_h, scr_x, main_h, 0),
COMMAND_VIEW => View::CommandView.new(c_scr, cmd_h, scr_x, main_h + detail_h, 0)
}
items = Qiita.items
@views[MAIN_VIEW].collection = items
@views[MAIN_VIEW].print
end
|
Instance Attribute Details
#views ⇒ Object
Returns the value of attribute views.
15
16
17
|
# File 'lib/tiqbi/view_controller.rb', line 15
def views
@views
end
|
Instance Method Details
#current_view ⇒ Object
60
61
62
|
# File 'lib/tiqbi/view_controller.rb', line 60
def current_view
@current_view ||= view(MAIN_VIEW)
end
|
#current_view=(v) ⇒ Object
64
65
66
|
# File 'lib/tiqbi/view_controller.rb', line 64
def current_view=(v)
@current_view = v
end
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/tiqbi/view_controller.rb', line 36
def on_input(input)
case input
when ?j
current_view.cursor_down
when ?k
current_view.cursor_up
when 10
if current_view == view(MAIN_VIEW)
index = current_view.cursor.y
item = current_view.collection.at(index)
return unless item
item_detail = Qiita.item(item.uuid)
view(DETAIL_VIEW).item_loaded item_detail
switch_to_next_view view(DETAIL_VIEW)
end
when ?q
switch_to_previous_view
end
end
|
#switch_to(v) ⇒ Object
88
89
90
91
92
|
# File 'lib/tiqbi/view_controller.rb', line 88
def switch_to(v)
self.current_view = v
v.setpos(v.cursor.y, v.cursor.x)
v.refresh
end
|
#switch_to_next_view(v) ⇒ Object
72
73
74
75
76
|
# File 'lib/tiqbi/view_controller.rb', line 72
def switch_to_next_view(v)
view_history << current_view
self.current_view = v
switch_to(current_view)
end
|
#switch_to_previous_view ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/tiqbi/view_controller.rb', line 78
def switch_to_previous_view
previous_view = view_history.shift
unless previous_view
exit
else
current_view.virtual_close
switch_to(previous_view)
end
end
|
#view(view_id) ⇒ Object
56
57
58
|
# File 'lib/tiqbi/view_controller.rb', line 56
def view(view_id)
views[view_id]
end
|
#view_history ⇒ Object
68
69
70
|
# File 'lib/tiqbi/view_controller.rb', line 68
def view_history
@view_history ||= []
end
|