zashoku 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e99bb8738a8d367c416d66c40130b91e07e9a76
4
- data.tar.gz: f45b7cef607b9e640d89dec4999976c178918cd8
3
+ metadata.gz: 36127e84b436a6174ad67764767744b9f3950c7c
4
+ data.tar.gz: ede097cbf3e0dafd9b6ccfd9e88c57f67d94d586
5
5
  SHA512:
6
- metadata.gz: ab0df30b379d34a69274ca6ba17f63a1dd42ada0d52f1a1413fb7039d40d900bc9bf888b0faa4b1e41b5fbd419c6a9168b809e13032b9dff45032877e7252ed0
7
- data.tar.gz: a40c62b9937bd0a060285324667d88b9498e7d8992cb3e849543cb5e98a98bdc31312285eace7c57ee09896324d48e8993f8d58ec221c2a17559c8605cb3ac08
6
+ metadata.gz: b94e35a3a766bb973f70480c17a9cdcca2c9bf502668c5540292f318da512e0e4cdf4dbeb0faf2d81d15cde5d3b3192aec9a6b2bc94d8c30fed367e78c44c973
7
+ data.tar.gz: 3041135e992d7b6f880b10c0f990e65dda2c374c7387222d3dfd44e0ef2fe211cd581004d197370a624841ed70a12cee17102efa28a7e7753fdbf167b556c9ba
@@ -14,14 +14,22 @@ module Zashoku
14
14
  1 => ''
15
15
  }.freeze
16
16
 
17
+ STRIP_BRACKETS = /\s*\[.+?\]\s*/
18
+ STRIP_EXT = /(\.mkv)|(\.avi)|(\.mp4)/
19
+ STRIP_PARENS = /\s*\(.+?\)\s*/
20
+
17
21
  def self.round(n, precision = 10.0)
18
22
  (Float(n) * precision).round / precision
19
23
  end
20
24
 
21
25
  def self.duration(secs)
22
- [secs / 3_600, (secs / 60) % 60, secs % 60].map do |i|
23
- i.round.to_s.rjust(2, '0')
24
- end.join(":")
26
+ [
27
+ secs >= 3_600 ? secs / 3_600 : nil,
28
+ (secs / 60) % 60,
29
+ secs % 60
30
+ ].map do |i|
31
+ i.round.to_s.rjust(2, '0') if i
32
+ end.compact.join(":")
25
33
  end
26
34
 
27
35
  def self.size(bytes)
@@ -35,6 +43,14 @@ module Zashoku
35
43
  "#{Integer(progress)}.#{Integer(progress * 10.0) % 10}"
36
44
  end
37
45
 
46
+ def self.media_file(path)
47
+ File.basename(path.to_s)
48
+ .gsub(STRIP_BRACKETS) {}
49
+ .gsub(STRIP_EXT, '')
50
+ .tr('_', ' ')
51
+ .gsub(STRIP_PARENS) {}
52
+ end
53
+
38
54
  def self.items(format, items)
39
55
  items.map do |parent, children|
40
56
  [
@@ -99,7 +99,9 @@ module Zashoku
99
99
  else
100
100
  @result_queue << response
101
101
  end
102
- rescue
102
+ rescue JSON::ParserError
103
+ Zashoku.logger.debug("discarding #{response}, JSON::ParserError")
104
+ rescue EOFError
103
105
  lost_connection
104
106
  end
105
107
 
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'widget'
4
+
5
+ module Zashoku
6
+ module Statusline
7
+ def self.new
8
+ Zashoku.logger.debug('statusline.new')
9
+ Zashoku::Statusline::Statusline.new
10
+ end
11
+
12
+ class Statusline
13
+ include Observable
14
+
15
+ def initialize
16
+ Zashoku.logger.debug('hhh')
17
+ @widgets = Zashoku.modules.keys.zip(Zashoku.modules.map do |_k, m|
18
+ m.widgets if m.respond_to?(:widgets)
19
+ end).to_h.compact
20
+ Zashoku.logger.debug(@widgets)
21
+ refresh
22
+ end
23
+
24
+ def changed!
25
+ changed
26
+ notify_observers
27
+ end
28
+
29
+ def event(event)
30
+ case event['event']
31
+ when 'refresh_widget'
32
+ @widgets[event['sender']][event['widget']].refresh
33
+ refresh
34
+ changed!
35
+ end
36
+ end
37
+
38
+ def refresh
39
+ @items = @widgets.map do |_k, m|
40
+ m.map { |_j, w| w.item }
41
+ end.flatten
42
+
43
+ @items_formatted = @items.join(' | ')
44
+ end
45
+
46
+ def draw
47
+ print "\e[#{Util::Term.rows - 1};1H\e[0m#{@items_formatted}\e[K"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ module Zashoku
2
+ module Statusline
3
+ class Widget
4
+ def intiailize; end
5
+
6
+ def refresh; end
7
+
8
+ def item
9
+ ''
10
+ end
11
+ end
12
+ end
13
+ end
@@ -40,7 +40,6 @@ module Zashoku
40
40
  def self.get_yaml(file)
41
41
  YAML.safe_load(File.open(file, 'r', &:read)) || {}
42
42
  rescue Errno::ENOENT
43
- puts 'failed'
44
43
  {}
45
44
  end
46
45
  end
data/lib/daemon.rb CHANGED
@@ -57,9 +57,9 @@ module Zashoku
57
57
  sleep
58
58
  end
59
59
 
60
- def update(sender:, event:)
61
- Zashoku.logger.debug("controller #{sender} sent update #{event}")
62
- @server.event(sender: sender, event: event)
60
+ def update(e)
61
+ Zashoku.logger.debug("controller #{e['sender']} sent update #{e['event']}")
62
+ @server.event(e)
63
63
  end
64
64
 
65
65
  def respond(message)
data/lib/viewer.rb CHANGED
@@ -10,6 +10,7 @@ require 'thread'
10
10
  require_relative 'core/controller'
11
11
  require_relative 'core/config/view_config'
12
12
  require_relative 'core/net/client'
13
+ require_relative 'core/statusline/statusline'
13
14
  require_relative 'core/util/term'
14
15
  require_relative 'core/util/util'
15
16
  require_relative 'core/formatter'
@@ -70,12 +71,16 @@ module Zashoku
70
71
  end).to_h
71
72
  @view = @views.keys.first
72
73
 
74
+ @statusline = Statusline.new
75
+ @statusline.add_observer(self, :draw_statusline)
76
+
73
77
  init_screen
74
78
  lay_traps!
75
79
  Thread.abort_on_exception = true
76
80
  Thread.new { scan_keyboard! }
77
81
 
78
82
  init_view(@view) if @view
83
+ @statusline.draw
79
84
  sleep
80
85
  end
81
86
 
@@ -118,6 +123,8 @@ module Zashoku
118
123
  end
119
124
 
120
125
  def handle_event(event)
126
+ return @statusline.event(event) if event['statusline']
127
+
121
128
  case event['event']
122
129
  when 'items'
123
130
  command(event['sender'], :refresh)
@@ -140,7 +147,6 @@ module Zashoku
140
147
  return send(COMMANDS[cmd]) if COMMANDS.key?(cmd)
141
148
 
142
149
  mod, meth, *args = cmd.split
143
- # puts "#{key} #{mod} #{meth} #{args}"
144
150
  mod = mod == 'current_view' ? @view : mod
145
151
  args.map! do |arg|
146
152
  if arg.chr == '$'
@@ -178,5 +184,9 @@ module Zashoku
178
184
  def draw_view
179
185
  @views[@view].draw
180
186
  end
187
+
188
+ def draw_statusline
189
+ @statusline.draw
190
+ end
181
191
  end
182
192
  end
data/lib/zashoku.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require_relative 'core/options'
4
4
 
5
5
  module Zashoku
6
- Version = [1, 1, 0].freeze
6
+ Version = [1, 2, 0].freeze
7
7
  Root = File.expand_path('../', __dir__)
8
8
 
9
9
  AppRoot = Root unless const_defined?(:AppRoot)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zashoku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - annacrombie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2017-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -110,6 +110,8 @@ files:
110
110
  - "./lib/core/net/client.rb"
111
111
  - "./lib/core/net/server.rb"
112
112
  - "./lib/core/options.rb"
113
+ - "./lib/core/statusline/statusline.rb"
114
+ - "./lib/core/statusline/widget.rb"
113
115
  - "./lib/core/util/folder_listen.rb"
114
116
  - "./lib/core/util/term.rb"
115
117
  - "./lib/core/util/util.rb"