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 +4 -4
- data/lib/core/formatter.rb +19 -3
- data/lib/core/net/client.rb +3 -1
- data/lib/core/statusline/statusline.rb +51 -0
- data/lib/core/statusline/widget.rb +13 -0
- data/lib/core/util/util.rb +0 -1
- data/lib/daemon.rb +3 -3
- data/lib/viewer.rb +11 -1
- data/lib/zashoku.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36127e84b436a6174ad67764767744b9f3950c7c
|
4
|
+
data.tar.gz: ede097cbf3e0dafd9b6ccfd9e88c57f67d94d586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b94e35a3a766bb973f70480c17a9cdcca2c9bf502668c5540292f318da512e0e4cdf4dbeb0faf2d81d15cde5d3b3192aec9a6b2bc94d8c30fed367e78c44c973
|
7
|
+
data.tar.gz: 3041135e992d7b6f880b10c0f990e65dda2c374c7387222d3dfd44e0ef2fe211cd581004d197370a624841ed70a12cee17102efa28a7e7753fdbf167b556c9ba
|
data/lib/core/formatter.rb
CHANGED
@@ -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
|
-
[
|
23
|
-
|
24
|
-
|
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
|
[
|
data/lib/core/net/client.rb
CHANGED
@@ -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
|
data/lib/core/util/util.rb
CHANGED
data/lib/daemon.rb
CHANGED
@@ -57,9 +57,9 @@ module Zashoku
|
|
57
57
|
sleep
|
58
58
|
end
|
59
59
|
|
60
|
-
def update(
|
61
|
-
Zashoku.logger.debug("controller #{sender} sent update #{event}")
|
62
|
-
@server.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
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.
|
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-
|
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"
|