aniview 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aniviewd +20 -0
- data/lib/aniview.rb +99 -47
- data/lib/aniview/client/aniclient.rb +11 -1
- data/lib/aniview/interface/animeio/animeio.rb +3 -2
- data/lib/aniview/interface/deluge/delugec.rb +13 -7
- data/lib/aniview/interface/mpv/mpvbridge.rb +80 -0
- data/lib/aniview/interface/pref/defaults.json +5 -3
- data/lib/aniview/interface/pref/pref.rb +2 -2
- data/lib/aniview/interface/pref/validate.json +3 -1
- data/lib/aniview/interface/schedule/schedule.rb +23 -3
- data/lib/aniview/interface/schedule/scheduleitem.rb +11 -1
- data/lib/aniview/interface/subscription/subscription.rb +32 -16
- data/lib/aniview/util/alogger.rb +1 -1
- data/lib/aniview/util/command.rb +2 -1
- data/lib/aniview/util/format.rb +7 -5
- data/lib/aniview/util/serializer.rb +19 -0
- data/lib/aniview/view/aiomenu.rb +2 -2
- data/lib/aniview/view/color.rb +67 -0
- data/lib/aniview/view/delugemenu.rb +4 -0
- data/lib/aniview/view/emote.rb +343 -95
- data/lib/aniview/view/menu.rb +300 -281
- data/lib/aniview/view/statusline.rb +18 -0
- data/lib/aniview/view/subscriptionmenu.rb +8 -5
- data/lib/aniviewd.rb +31 -19
- metadata +13 -8
- data/lib/aniview/interface/subscription/subscriptiondaemon.rb +0 -42
data/lib/aniview/view/menu.rb
CHANGED
@@ -1,286 +1,305 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'color'
|
2
2
|
require_relative '../util/alogger'
|
3
3
|
require_relative '../util/format'
|
4
4
|
|
5
5
|
class Menu
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
198
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
end
|
7
|
+
def initialize(refresh_function:,interface:,name:,pref:,format:,term:,children: true)
|
8
|
+
@term = term
|
9
|
+
@format = format
|
10
|
+
@attributes = {
|
11
|
+
"t" => name,
|
12
|
+
}
|
13
|
+
@pref = pref
|
14
|
+
@refresh_func = refresh_function
|
15
|
+
@interface = interface
|
16
|
+
@expanded = -1
|
17
|
+
@selected = 0
|
18
|
+
@children = children
|
19
|
+
@items_formatted = {}
|
20
|
+
@items_hash = {}
|
21
|
+
@hashmap = {}
|
22
|
+
@lu = 0
|
23
|
+
|
24
|
+
@oldRows = @term.rows
|
25
|
+
@logger = ALogger.new("/dev/null", true)
|
26
|
+
|
27
|
+
refresh
|
28
|
+
@lastcount = getLen
|
29
|
+
|
30
|
+
@view = [0, @term.rows - 3]
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def setRfunc(name)
|
35
|
+
@refresh_func = name
|
36
|
+
@items_formatted = {}
|
37
|
+
@items_hash = {}
|
38
|
+
@lu = 0
|
39
|
+
refresh
|
40
|
+
refreshFormats
|
41
|
+
end
|
42
|
+
|
43
|
+
def change_screen_size
|
44
|
+
#@term.rows = lines
|
45
|
+
#@term.cols = cols
|
46
|
+
@items_formatted = {}
|
47
|
+
@items_hash = {}
|
48
|
+
@lu = 0
|
49
|
+
refresh
|
50
|
+
|
51
|
+
#if @term.rows > @oldRows
|
52
|
+
|
53
|
+
diff = @term.rows - @oldRows
|
54
|
+
#@view[0] += diff
|
55
|
+
@view[1] += diff
|
56
|
+
|
57
|
+
@oldRows = @term.rows
|
58
|
+
adjustView
|
59
|
+
draw
|
60
|
+
end
|
61
|
+
|
62
|
+
def setName(name)
|
63
|
+
@attributes["t"] = name
|
64
|
+
end
|
65
|
+
|
66
|
+
def setFormat(format_)
|
67
|
+
@format = format_
|
68
|
+
end
|
69
|
+
|
70
|
+
def refresh
|
71
|
+
@items = @interface.makeHash @interface.send(@refresh_func)
|
72
|
+
@expanded = -1 if @items.values[@expanded] == nil
|
73
|
+
fixCursor
|
74
|
+
end
|
75
|
+
|
76
|
+
def expand(i)
|
77
|
+
return if i > @items.length
|
78
|
+
if @expanded == i
|
79
|
+
@selected = @expanded
|
80
|
+
@expanded = -1
|
81
|
+
else
|
82
|
+
@selected = i
|
83
|
+
@expanded = i
|
84
|
+
end
|
85
|
+
fixCursor
|
86
|
+
adjustView
|
87
|
+
end
|
88
|
+
|
89
|
+
def resolveSelected(resolve_me=@selected)
|
90
|
+
in_expanded=false
|
91
|
+
inside = 0
|
92
|
+
outside = resolve_me
|
93
|
+
if @expanded > -1
|
94
|
+
if resolve_me > @expanded and resolve_me <= (@items.values[@expanded].length + @expanded)
|
95
|
+
outside = @expanded
|
96
|
+
inside = resolve_me - @expanded - 1
|
97
|
+
in_expanded=true
|
98
|
+
elsif resolve_me > @expanded
|
99
|
+
outside = resolve_me - @items.values[@expanded].length
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
return Hash["out" => outside, "in" => inside, "in_expanded" => in_expanded]
|
104
|
+
end
|
105
|
+
|
106
|
+
def moveCursor(dir)
|
107
|
+
@selected -= 1 if dir == "up"
|
108
|
+
@selected += 1 if dir == "down"
|
109
|
+
adjustView
|
110
|
+
fixCursor
|
111
|
+
end
|
112
|
+
|
113
|
+
def fixCursor
|
114
|
+
#wrap selector
|
115
|
+
#@selected = getLen - 1 if @selected < 0
|
116
|
+
#@selected = 0 if @selected >= getLen
|
117
|
+
#
|
118
|
+
#nowrap
|
119
|
+
@selected = 0 if @selected < 0
|
120
|
+
@selected = getLen - 1 if @selected >= getLen
|
121
|
+
end
|
122
|
+
|
123
|
+
def getLen
|
124
|
+
len = @items.length
|
125
|
+
len += @items.values[@expanded].length if @expanded >= 0
|
126
|
+
return len
|
127
|
+
end
|
128
|
+
|
129
|
+
def color(index)
|
130
|
+
if index == @selected
|
131
|
+
return Color.public_send(@pref.get("clr")["selected"])
|
132
|
+
else
|
133
|
+
return Color.public_send(@pref.get("clr")["secondary"])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def refreshFormats
|
138
|
+
now = Integer(DateTime.now.strftime('%Q'))
|
139
|
+
return if now - @lu < 100
|
140
|
+
@lu = now
|
141
|
+
|
142
|
+
@cl = {
|
143
|
+
"s" => Color.public_send(@pref.get("clr")["selected"]),
|
144
|
+
"1" => Color.public_send(@pref.get("clr")["primary"]),
|
145
|
+
"2" => Color.public_send(@pref.get("clr")["secondary"]),
|
146
|
+
"m" => Color.public_send(@pref.get("clr")["main"]),
|
147
|
+
}
|
148
|
+
|
149
|
+
#@items_formatted = {}
|
150
|
+
new_items_formatted = {}
|
151
|
+
new_items_hash = {}
|
152
|
+
new_hashmap = {}
|
153
|
+
@items.each_with_index { |item, i|
|
154
|
+
|
155
|
+
#@l.log @items.keys[i]
|
156
|
+
#
|
157
|
+
babble = item[0].cereal #Digest::SHA256.bubblebabble String(item[0])
|
158
|
+
|
159
|
+
if @items_hash.key? babble
|
160
|
+
val = @items_hash[babble]
|
161
|
+
new_items_hash.merge!(babble => val)
|
162
|
+
new_items_formatted.merge!(@hashmap[babble] => @items_formatted[@hashmap[babble]])
|
163
|
+
new_hashmap.merge!(babble => @hashmap[babble])
|
164
|
+
next
|
165
|
+
end
|
166
|
+
|
167
|
+
parent = Format.parse_format(
|
168
|
+
@pref.get(@format)["parent"],
|
169
|
+
item[0].attributes,
|
170
|
+
@term.cols
|
171
|
+
)
|
172
|
+
|
173
|
+
children = []
|
174
|
+
children_hash = []
|
175
|
+
|
176
|
+
if @children
|
177
|
+
item[1].each { |subitem|
|
178
|
+
|
179
|
+
child_babble = subitem.cereal
|
180
|
+
|
181
|
+
if @items_hash.key? child_babble
|
182
|
+
val = @items_hash[babble]
|
183
|
+
new_items_hash.merge!(child_babble => val)
|
184
|
+
children<<@hashmap[babble]
|
185
|
+
new_hashmap.merge!(babble => @hashmap[babble])
|
186
|
+
next
|
187
|
+
end
|
188
|
+
|
189
|
+
children << Format.parse_format(
|
190
|
+
@pref.get(@format)["child"],
|
191
|
+
subitem.attributes,
|
192
|
+
@term.cols
|
193
|
+
)
|
194
|
+
children_hash << subitem.hash
|
195
|
+
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
new_items_hash.merge!(babble => children_hash)
|
200
|
+
new_items_formatted.merge!(parent => children)
|
201
|
+
new_hashmap.merge!(babble => parent)
|
202
|
+
}
|
203
|
+
|
204
|
+
@items_formatted = new_items_formatted
|
205
|
+
@items_hash = new_items_hash
|
206
|
+
@hashmap = new_hashmap
|
207
|
+
|
208
|
+
@title_formatted = Format.parse_format(
|
209
|
+
@pref.get(@format)["title"],
|
210
|
+
@attributes,
|
211
|
+
@term.cols
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
215
|
+
def adjustView
|
216
|
+
buffer = 2
|
217
|
+
bottom = @term.rows-3
|
218
|
+
|
219
|
+
diff = 0
|
220
|
+
#@logger.log("pre first loop: #{@selected}, #{buffer}, #{@view}")
|
221
|
+
if @selected < @view[0] + buffer #and @selected > buffer
|
222
|
+
while @selected < @view[0] + buffer
|
223
|
+
@view[0]-=1
|
224
|
+
@view[1]-=1
|
225
|
+
@logger.log("first loop: #{@selected}, #{@view}")
|
226
|
+
end
|
227
|
+
elsif @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
|
228
|
+
@logger.log("")
|
229
|
+
while @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
|
230
|
+
@logger.log("second loop: #{@selected}, #{@view}")
|
231
|
+
@view[0]+=1
|
232
|
+
@view[1]+=1
|
233
|
+
@logger.log("-----------: #{@selected}, #{@view}")
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
@logger.log("#{@selected}, #{@view}")
|
238
|
+
|
239
|
+
diff = 0 - @view[0] if @view[0] < 0
|
240
|
+
diff = bottom - @view[1] if @view[1] < bottom
|
241
|
+
|
242
|
+
@view[0] += diff
|
243
|
+
@view[1] += diff
|
244
|
+
end
|
245
|
+
|
246
|
+
def draw
|
247
|
+
refreshFormats
|
248
|
+
drawFrom(@view[0], @view[1])
|
249
|
+
end
|
250
|
+
|
251
|
+
def drawFrom(line_on, lines_to_draw)
|
252
|
+
#print menu header
|
253
|
+
lo="\e[1;1H"
|
254
|
+
print lo + @cl["m"] + @title_formatted + "\e[K"
|
255
|
+
|
256
|
+
resolved_start_position = resolveSelected line_on
|
257
|
+
|
258
|
+
outer_index = resolved_start_position["out"]
|
259
|
+
inner_index = resolved_start_position["in"]
|
260
|
+
|
261
|
+
if resolved_start_position["in_expanded"]
|
262
|
+
outer_index+=1
|
263
|
+
end
|
264
|
+
|
265
|
+
offset=line_on-1
|
266
|
+
|
267
|
+
while line_on < lines_to_draw
|
268
|
+
|
269
|
+
in_outer_region = ! (line_on >= getLen)
|
270
|
+
in_expanded_region = resolveSelected(line_on)["in_expanded"]
|
271
|
+
line = line_on-offset+1
|
272
|
+
selected = line_on == @selected
|
273
|
+
|
274
|
+
cl = ""
|
275
|
+
cl = @cl["s"] if selected
|
276
|
+
lo = "\e[#{line};1H" + cl
|
277
|
+
|
278
|
+
if in_expanded_region and @children
|
279
|
+
print @cl["2"] + lo + String(@items_formatted.values[@expanded][inner_index]) + "\e[K" unless @items_formatted.values[@expanded] == nil
|
280
|
+
inner_index+=1
|
281
|
+
elsif in_outer_region
|
282
|
+
print @cl["1"] + lo + String(@items_formatted.keys[outer_index]) + "\e[K"
|
283
|
+
outer_index+=1
|
284
|
+
else
|
285
|
+
print "\e[#{line};1H\e[2K\n"
|
286
|
+
end
|
287
|
+
|
288
|
+
line_on+=1
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def control(key)
|
293
|
+
sel = resolveSelected
|
294
|
+
if key == @pref.get("keybindings")["menu_nav_up"]
|
295
|
+
moveCursor("up")
|
296
|
+
elsif key == @pref.get("keybindings")["menu_nav_down"]
|
297
|
+
moveCursor("down")
|
298
|
+
else
|
299
|
+
customControl(key, sel)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def customControl(key, sel); end
|
304
|
+
|
305
|
+
end
|