aniview 2.1.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,34 +5,18 @@ module Aniview
5
5
  module View
6
6
  class PrefMenu < Menu
7
7
  include Aniview::Util
8
- def refresh
9
- @items = @interface.send(@refresh_function)
10
8
 
11
- @attributes = {
12
- "t" => @attributes["t"],
13
- }
14
-
15
- @expanded = -1 if @items.values[@expanded] == nil
16
- fixCursor
17
- end
18
-
19
- def customControl(key, sel)
20
- path = @items.values[sel["out"]][0].path
21
- title = @items.keys[sel["out"]].attributes["t"]
22
- value = @items.keys[sel["out"]].attributes["v"]
23
-
24
- if key == "space"
25
- #expand(sel["out"])
26
- elsif key == "r"
27
- refresh
28
- elsif key == "enter"
29
-
30
- newval = Util.readline(@term, title + ":", value)
31
-
32
- @interface.set(path, newval)
33
- refresh
34
- end
35
- end
9
+ def customControl(key, sel)
10
+ return if @items.keys[sel["out"]].attributes["t"] == ""
11
+ path = @items.values[sel["out"]][0].path
12
+ title = @items.keys[sel["out"]].attributes["t"]
13
+ value = @items.keys[sel["out"]].attributes["v"]
14
+ if key == "enter"
15
+ newval = Util.readline(@term, title + ":", value)
16
+ @interface.set(path, newval)
17
+ refresh
18
+ end
19
+ end
36
20
  end
37
21
  end
38
22
  end
@@ -5,16 +5,6 @@ module Aniview
5
5
  module View
6
6
  class ScheduleMenu < Menu
7
7
  include Aniview::Util
8
- def refresh
9
- @items = @interface.makeHash @interface.send(@refresh_function)
10
-
11
- @attributes = {
12
- "t" => @attributes["t"],
13
- }
14
-
15
- @expanded = -1 if @items.values[@expanded] == nil
16
- fixCursor
17
- end
18
8
 
19
9
  def customControl(key, sel)
20
10
 
@@ -33,7 +23,6 @@ module Aniview
33
23
 
34
24
  end
35
25
  end
36
-
37
26
  end
38
27
  end
39
28
  end
@@ -4,20 +4,57 @@ require_relative 'color'
4
4
  module Aniview
5
5
  module View
6
6
  class StatusLine
7
+
7
8
  include Aniview::Util
9
+ include Observable
10
+
8
11
  def initialize pref, term, mpvbridge
9
12
  @term = term
10
13
  @pref = pref
11
14
  @mpvbridge = mpvbridge
15
+
16
+ @mpvbridge.add_observer(self, :draw)
17
+
12
18
  @clr = Aniview::View::Color.public_send(@pref.get("clr")["main"])
19
+ reset_message
13
20
  end
14
-
21
+
22
+ def message msg, display_for: 1, color: "red"
23
+ @message = {
24
+ "text" => msg,
25
+ "linger" => display_for,
26
+ "color" => color
27
+ }
28
+ changed
29
+ notify_observers
30
+ end
31
+
32
+ def reset_message
33
+ @message = {
34
+ "text" => nil,
35
+ "linger" => 0,
36
+ "color" => "red"
37
+ }
38
+ changed
39
+ notify_observers
40
+ end
41
+
42
+ def print_row line
43
+ print "\e[#{@term.rows - 1};1H" + @clr + line + "\e[K\nq\e[2K"
44
+ end
45
+
15
46
  def draw
16
- status_row = @term.rows - 1
17
- line = Util.parse_format @pref.get("format_status"), @mpvbridge.attributes, @term.cols
18
- #p @mpvbridge.attributes
19
- print "\e[#{status_row};1H" + @clr + line + "\e[K\n\e[2K"
47
+ if @message["text"] == nil
48
+ line = Util.parse_format @pref.get("format_status"), @mpvbridge.attributes, @term.cols
49
+ print_row line
50
+ else
51
+ line = Color.public_send(@message["color"]) + @message["text"]
52
+ print_row line
53
+ sleep Integer(@message["linger"])
54
+ reset_message
55
+ end
20
56
  end
57
+
21
58
  end
22
59
  end
23
60
  end
@@ -4,38 +4,34 @@ require_relative '../util/util'
4
4
  module Aniview
5
5
  module View
6
6
  class SubscriptionMenu < Menu
7
-
7
+
8
8
  include Aniview::Util
9
9
 
10
- def refresh
11
- @last_checked = Time.now.to_i if @last_checked == nil
12
-
13
- @items = @interface.makeHash @interface.send(@refresh_function)
14
-
15
- if Time.now.to_i < @last_checked + 10
16
- @attributes["l"] = @interface.getLastChecked
17
- @attributes["d"] = @interface.checkDaemon
18
- @interface.syncMatches
19
- @last_checked = Time.now.to_i
20
- end
21
-
22
- @expanded = -1 if @items.values[@expanded] == nil
23
- fixCursor
10
+ #if Time.now.to_i < @last_checked + 10
11
+ # @last_checked = Time.now.to_i
12
+ #end
13
+
14
+ def refresh_attributes
15
+ @attributes["l"] = @interface.getLastChecked
16
+ @attributes["d"] = @interface.checkDaemon
17
+ @attributes["n"] = @interface.getNextCheck
18
+ @interface.syncMatches
24
19
  end
25
-
20
+
26
21
  def customControl(key, sel)
27
-
22
+
28
23
  item = @items.values[sel["out"]].attributes["r"]
29
-
24
+
30
25
  if key == @pref.get("keybindings")["subscriptions_edit"]
31
26
  newval = Util.readline(@term, "regexp:", item)
32
27
  @interface.editItem(sel["out"], newval)
33
-
28
+
34
29
  elsif key == "m"
35
30
  @interface.forceMatch
36
31
 
37
32
  end
38
- end
33
+ end
34
+
39
35
  end
40
36
  end
41
37
  end
data/lib/application.rb CHANGED
@@ -3,6 +3,10 @@ require 'highline/import'
3
3
  require 'thread'
4
4
  require 'io/console'
5
5
  require 'warning'
6
+ require 'observer'
7
+ require 'benchmark'
8
+
9
+ require 'logger'
6
10
 
7
11
  Warning.ignore([:fixnum, :bignum])
8
12
 
@@ -37,35 +41,29 @@ module Aniview
37
41
  # @return nil
38
42
  #
39
43
  def initialize
40
-
44
+
45
+ #@logger = Logger.new('aniview.log')
46
+ #@logger.level = Logger::DEBUG
47
+
41
48
  @term = Util::Term.new
42
49
 
43
50
  @pref = Interface::Pref.new
44
51
 
45
- @mpvbridge = Interface::MPVBridge.new @pref
46
-
47
- @aio = Interface::AnimeIO.new @pref, @mpvbridge
48
-
49
- @schedule = Interface::Schedule.new @pref
50
-
51
- @delugec = Interface::DelugeC.new @pref
52
-
53
- @c = Client::AniClient.new @pref
54
-
55
- @statusline = View::StatusLine.new @pref, @term, @mpvbridge
56
-
57
- #file = "/Users/lattis/anime/Tekkonkinkreet/Tekkonkinkreet.mkv"
58
- #@mpvbridge.play file
59
-
60
- #while true
61
- # @statusline.draw
62
- # sleep 1/45.0
63
- #end
64
-
65
- @subscription = Interface::Subscription.new(@pref, @schedule, @delugec, @c)
66
-
52
+ @mpvbridge = Interface::MPVBridge.new @pref
53
+
54
+ @aio = Interface::AnimeIO.new @pref, @mpvbridge
55
+
56
+ @schedule = Interface::Schedule.new @pref
57
+
58
+ @delugec = Interface::DelugeC.new @pref
59
+
60
+ @c = Client::AniClient.new @pref
61
+
62
+ @statusline = View::StatusLine.new @pref, @term, @mpvbridge
63
+
64
+ @subscription = Interface::Subscription.new @pref, @schedule, @delugec, @c
65
+
67
66
  if not @c.server?
68
- #puts "starting server"
69
67
  process = fork do
70
68
  require_relative 'daemon'
71
69
  avd = Daemon.new([])
@@ -73,17 +71,16 @@ module Aniview
73
71
  end
74
72
  Process.detach(process)
75
73
  end
76
-
74
+
77
75
  @aiomenu = View::AioMenu.new(
78
- refresh_function: :getUnwatched,
79
76
  interface: @aio,
80
77
  name: @pref.get("menu_titles")["unwatched"],
81
78
  pref: @pref,
82
79
  format: "format_library_unwatched",
83
- term: @term
80
+ term: @term,
81
+ refresh_function: :unwatched
84
82
  )
85
83
  @prefmenu = View::PrefMenu.new(
86
- refresh_function: :getAll,
87
84
  interface: @pref,
88
85
  name: @pref.get("menu_titles")["preferences"],
89
86
  pref: @pref,
@@ -92,7 +89,6 @@ module Aniview
92
89
  children: false
93
90
  )
94
91
  @delugemenu = View::DelugeMenu.new(
95
- refresh_function: :getTorrents,
96
92
  interface: @delugec,
97
93
  name: @pref.get("menu_titles")["torrents"],
98
94
  pref: @pref,
@@ -100,19 +96,15 @@ module Aniview
100
96
  term: @term,
101
97
  children: false
102
98
  )
103
-
104
99
  @schedulemenu = View::ScheduleMenu.new(
105
- refresh_function: :getAll,
106
100
  interface: @schedule,
107
- name: @pref.get("menu_titles")["schedlue"],
101
+ name: @pref.get("menu_titles")["schedule"],
108
102
  pref: @pref,
109
103
  format: "format_schedule",
110
104
  term: @term,
111
105
  children: false
112
106
  )
113
-
114
107
  @subscriptionmenu = View::SubscriptionMenu.new(
115
- refresh_function: :getAll,
116
108
  interface: @subscription,
117
109
  name: @pref.get("menu_titles")["subscriptions"],
118
110
  pref: @pref,
@@ -120,8 +112,8 @@ module Aniview
120
112
  term: @term,
121
113
  children: false
122
114
  )
123
-
124
115
  @term.save.hide_cursor.echo_off
116
+
125
117
  end
126
118
 
127
119
  # Cleans up Aniview, restoring terminal settings and safely exiting all
@@ -130,10 +122,13 @@ module Aniview
130
122
  # @return nil
131
123
  #
132
124
  def cleanup
125
+ @view.pause
126
+ @statusthread.exit if @statusthread
133
127
  @mthread.exit if @mthread != nil
134
128
  @statusthread.exit if @statusthread != nil
135
129
  @term.reset
136
130
  @mpvbridge.quit!
131
+ @aio.cleanup
137
132
  exit
138
133
  end
139
134
 
@@ -161,8 +156,7 @@ module Aniview
161
156
  puts "Help"
162
157
  puts ""
163
158
  else
164
- print "\033[" + String(@term.rows) + ";1H" + Aniview::View::Color.red + "error, unknown command"
165
- @term.getKey
159
+ @statusline.message "unknown command"
166
160
  end
167
161
  end
168
162
 
@@ -173,48 +167,70 @@ module Aniview
173
167
  # @return nil
174
168
  #
175
169
  def changeView newView
170
+ @view.delete_observers
171
+ @view.pause
172
+ newView.unpause
173
+ newView.add_observer(self, :drawview)
174
+ newView.change_screen_size redraw: false
175
+ newView.expand -1
176
176
  @view = newView
177
- @view.change_screen_size
178
177
  end
179
178
 
179
+ def drawview
180
+ @view.draw
181
+ @rcount ||= 0
182
+ #puts "refreshed view #{@rcount+=1}"
183
+ end
184
+
185
+ def togglestatusline
186
+ return unless @mpvbridge.what_changed == "playing_status"
187
+ unless @statusthread
188
+ @statusthread = Thread.new do
189
+ while true
190
+ @statusline.draw
191
+ sleep 0.07
192
+ end
193
+ end
194
+ else
195
+ @statusthread.exit
196
+ @statusthread = nil
197
+ end
198
+ end
199
+
200
+ def drawmessage
201
+ unless @statusthread
202
+ @view.draw
203
+ Thread.new do
204
+ @statusline.draw
205
+ @statusline.draw
206
+ end
207
+ end
208
+ end
180
209
 
181
210
  # Runs the aniview application, this method starts all of the threads
182
211
  #
183
212
  # @return nil
184
213
  #
185
214
  def run
186
-
215
+
187
216
  @view = @aiomenu
188
-
217
+ @view.add_observer(self, :drawview)
218
+ @statusline.draw
219
+
220
+ @mpvbridge.add_observer(self, :togglestatusline)
221
+ @statusline.add_observer(self, :drawmessage)
222
+
189
223
  mutex = Mutex.new
190
224
  Signal.trap('SIGWINCH', proc {
191
- Thread.new { mutex.synchronize { @view.change_screen_size } }
225
+ Thread.new { mutex.synchronize {
226
+ @view.change_screen_size
227
+ @statusline.draw
228
+ } }
192
229
  } )
193
-
230
+
194
231
  key = ""
195
232
  @view.refresh
196
- @shoulddraw = true
197
-
198
- Thread.abort_on_exception = true
199
- @mthread = Thread.new do
200
- while true
201
- if @shoulddraw
202
- @view.draw
203
- @view.refresh
204
- end
205
- sleep 1/45.0
206
- end
207
- end
208
-
209
- @statusthread = Thread.new do
210
- while true
211
- if @shoulddraw
212
- @statusline.draw
213
- end
214
- sleep 1/25.0
215
- end
216
- end
217
-
233
+
218
234
  while true
219
235
  @shoulddraw = true
220
236
  key = @term.getKey
@@ -228,14 +244,12 @@ module Aniview
228
244
  changeView @aiomenu
229
245
  @view.setName nm["unwatched"]
230
246
  @view.setFormat("format_library_unwatched")
231
- @view.setRfunc(:getUnwatched)
232
-
247
+ @view.setRfunc(:unwatched)
233
248
  when kb["goto_library"]
234
249
  changeView @aiomenu
235
250
  @view.setName nm["library"]
236
251
  @view.setFormat("format_library")
237
- @view.setRfunc(:getAll)
238
-
252
+ @view.setRfunc(:items)
239
253
  when kb["goto_torrents"]
240
254
  changeView @delugemenu
241
255
  @view.setName nm["torrents"]
@@ -249,7 +263,14 @@ module Aniview
249
263
  changeView @subscriptionmenu
250
264
  @view.setName nm["subscriptions"]
251
265
  when ":"
266
+ @view.pause
267
+ if @statusthread
268
+ togglestatusline
269
+ toggled = true
270
+ end
252
271
  runCommand Util.readline(@term, ":")
272
+ togglestatusline if toggled
273
+ @view.unpause
253
274
  when "q"
254
275
  cleanup
255
276
  end