aniview 1.3.0 → 2.0.0

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