Module: Twterm::Tab::StatusesTab
Instance Attribute Summary
Attributes included from Base
#title
Instance Method Summary
collapse
Methods included from Scrollable
#draw_scroll_bar, #index, #item_appended, #item_prepended, #last, #move_down, #move_to_bottom, #move_to_top, #move_up, #offset, #update_scrollbar_length
Methods included from Base
#==, #close, #refresh
Instance Method Details
#append(status) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/twterm/tab/statuses_tab.rb', line 31
def append(status)
fail ArgumentError, 'argument must be an instance of Status class' unless status.is_a? Status
return if @status_ids.include?(status.id)
@status_ids.unshift(status.id)
status.split(@window.maxx - 4)
status.touch!
item_appended
refresh
end
|
#delete(status_id) ⇒ Object
77
78
79
80
|
# File 'lib/twterm/tab/statuses_tab.rb', line 77
def delete(status_id)
@status_ids.delete(status_id)
refresh
end
|
#destroy_status ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/twterm/tab/statuses_tab.rb', line 68
def destroy_status
status = highlighted_status
Client.current.destroy_status(status) do
delete(status.id)
refresh
end
end
|
#favorite ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/twterm/tab/statuses_tab.rb', line 48
def favorite
return if highlighted_status.nil?
if highlighted_status.favorited?
Client.current.unfavorite(highlighted_status) do
refresh
end
else
Client.current.favorite(highlighted_status) do
refresh
end
end
end
|
#fetch ⇒ Object
102
103
104
|
# File 'lib/twterm/tab/statuses_tab.rb', line 102
def fetch
fail NotImplementedError, 'fetch method must be implemented'
end
|
#initialize ⇒ Object
7
8
9
10
11
|
# File 'lib/twterm/tab/statuses_tab.rb', line 7
def initialize
super
@status_ids = []
end
|
#open_link ⇒ Object
89
90
91
92
93
94
|
# File 'lib/twterm/tab/statuses_tab.rb', line 89
def open_link
return if highlighted_status.nil?
status = highlighted_status
urls = status.urls.map(&:expanded_url) + status.media.map(&:expanded_url)
urls.each(&Launchy.method(:open))
end
|
#prepend(status) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/twterm/tab/statuses_tab.rb', line 19
def prepend(status)
fail unless status.is_a? Status
return if @status_ids.include?(status.id)
@status_ids << status.id
status.split(@window.maxx - 4)
status.touch!
item_prepended
refresh
end
|
#reply ⇒ Object
43
44
45
46
|
# File 'lib/twterm/tab/statuses_tab.rb', line 43
def reply
return if highlighted_status.nil?
Tweetbox.instance.compose(highlighted_status)
end
|
#respond_to_key(key) ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/twterm/tab/statuses_tab.rb', line 199
def respond_to_key(key)
return true if super
case key
when 'c'
show_conversation
when 'D'
destroy_status
when 'F'
favorite
when 'o'
open_link
when 'r'
reply
when 'R'
when 18
fetch
when 'U'
show_user
else
return false
end
true
end
|
61
62
63
64
65
66
|
# File 'lib/twterm/tab/statuses_tab.rb', line 61
def
return if highlighted_status.nil?
Client.current.(highlighted_status) do
refresh
end
end
|
#show_conversation ⇒ Object
96
97
98
99
100
|
# File 'lib/twterm/tab/statuses_tab.rb', line 96
def show_conversation
return if highlighted_status.nil?
tab = Tab::ConversationTab.new(highlighted_status.id)
TabManager.instance.add_and_show(tab)
end
|
#show_user ⇒ Object
82
83
84
85
86
87
|
# File 'lib/twterm/tab/statuses_tab.rb', line 82
def show_user
return if highlighted_status.nil?
user = highlighted_status.user
user_tab = Tab::UserTab.new(user.id)
TabManager.instance.add_and_show(user_tab)
end
|
#statuses ⇒ Object
13
14
15
16
17
|
# File 'lib/twterm/tab/statuses_tab.rb', line 13
def statuses
statuses = @status_ids.map { |id| Status.find(id) }.reject(&:nil?)
@status_ids = statuses.map(&:id)
statuses
end
|
#touch_statuses ⇒ Object
106
107
108
|
# File 'lib/twterm/tab/statuses_tab.rb', line 106
def touch_statuses
statuses.reverse.take(100).each(&:touch!)
end
|
#update ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/twterm/tab/statuses_tab.rb', line 110
def update
current_line = 0
@window.clear
return if offset < 0
statuses.reverse.drop(offset).each.with_index(offset) do |status, i|
formatted_lines = status.split(@window.maxx - 4).count
if current_line + formatted_lines + 2 > @window.maxy
@scrollable_last = i
break
end
posy = current_line
if index == i
@window.with_color(:black, :magenta) do
(formatted_lines + 1).times do |j|
@window.setpos(posy + j, 0)
@window.addch(' ')
end
end
end
@window.setpos(current_line, 2)
@window.bold do
@window.with_color(status.user.color) do
@window.addstr(status.user.name)
end
end
@window.addstr(" (@#{status.user.screen_name}) [#{status.date}] ")
unless status..nil?
@window.addstr('(retweeted by ')
@window.bold do
@window.addstr("@#{status..screen_name}")
end
@window.addstr(') ')
end
if status.favorited?
@window.with_color(:black, :yellow) do
@window.addch(' ')
end
@window.addch(' ')
end
if status.
@window.with_color(:black, :green) do
@window.addch(' ')
end
@window.addch(' ')
end
if status.favorite_count > 0
@window.with_color(:yellow) do
@window.addstr("#{status.favorite_count}fav#{status.favorite_count > 1 ? 's' : ''}")
end
@window.addch(' ')
end
if status. > 0
@window.with_color(:green) do
@window.addstr("#{status.}RT#{status. > 1 ? 's' : ''}")
end
@window.addch(' ')
end
status.split(@window.maxx - 4).each do |line|
current_line += 1
@window.setpos(current_line, 2)
@window.addstr(line)
end
current_line += 2
end
draw_scroll_bar
@window.refresh
UserWindow.instance.update(highlighted_status.user) unless highlighted_status.nil?
show_help
end
|