mikeplayer 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mikeplayer/display.rb +62 -11
- data/lib/mikeplayer/play_thread.rb +1 -0
- data/lib/mikeplayer/playlist.rb +2 -1
- data/lib/mikeplayer/version.rb +1 -1
- data/lib/mikeplayer.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc4762ff6cf9ce9e9cbbd87c1d46a92629faab94444a79423a9797ce257fc284
|
|
4
|
+
data.tar.gz: d629eb95a5a352242dc03b41a1565bf71089ef2bc8986519131f020db73a69fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b73c5011fea15ef7c33866d7abd727132a7f23b737c8985bbbf223e724517dcc8de6d17b592a83e9eb2f11035d585504fe499f2ca755fd0c457e9be83b4b0ecc
|
|
7
|
+
data.tar.gz: 80cad1d3712f04b2886a1dca59fa850aa9fb6c8b3497759e9e61fed8048389465e198c0e20e58c6fd3e65a69f5bb681c3d4e47a0c864ab40775faba7c0698aa1
|
data/lib/mikeplayer/display.rb
CHANGED
|
@@ -2,6 +2,13 @@ module MikePlayer
|
|
|
2
2
|
class Display
|
|
3
3
|
PAUSE_INDICATOR = '||'.freeze
|
|
4
4
|
INDICATOR_SIZE = 4
|
|
5
|
+
PROGRESS_WIDTH = 40
|
|
6
|
+
|
|
7
|
+
TITLE_ROW = 4
|
|
8
|
+
BAR_ROW = 5
|
|
9
|
+
HINT_ROW = 7
|
|
10
|
+
|
|
11
|
+
HINT_TEXT = 'c: pause/play v: next z: previous t: set timer q: quit'.freeze
|
|
5
12
|
|
|
6
13
|
RESET = "\e[0m".freeze
|
|
7
14
|
TITLE_COLOR = "\e[1;36m".freeze # bold cyan
|
|
@@ -12,8 +19,8 @@ module MikePlayer
|
|
|
12
19
|
PLAY_COLOR = "\e[32m".freeze # green
|
|
13
20
|
PAUSE_COLOR = "\e[1;31m".freeze # bold red
|
|
14
21
|
|
|
15
|
-
ENTER_ALT_SCREEN = "\e[?1049h\e[2J\e[H".freeze
|
|
16
|
-
EXIT_ALT_SCREEN = "\e[?1049l".freeze
|
|
22
|
+
ENTER_ALT_SCREEN = "\e[?1049h\e[2J\e[H\e[?25l".freeze
|
|
23
|
+
EXIT_ALT_SCREEN = "\e[?25h\e[?1049l".freeze
|
|
17
24
|
|
|
18
25
|
def self.colorize(text, color)
|
|
19
26
|
return text unless $stdout.tty?
|
|
@@ -31,20 +38,25 @@ module MikePlayer
|
|
|
31
38
|
$stdout.flush
|
|
32
39
|
end
|
|
33
40
|
|
|
34
|
-
def initialize
|
|
35
|
-
@width
|
|
36
|
-
@indicator
|
|
37
|
-
@paused
|
|
38
|
-
@changed
|
|
39
|
-
@color
|
|
41
|
+
def initialize(fullscreen: false)
|
|
42
|
+
@width = 0
|
|
43
|
+
@indicator = ''
|
|
44
|
+
@paused = false
|
|
45
|
+
@changed = false
|
|
46
|
+
@color = $stdout.tty?
|
|
47
|
+
@fullscreen = fullscreen
|
|
48
|
+
@elapsed_seconds = 0
|
|
49
|
+
@length = 0
|
|
40
50
|
end
|
|
41
51
|
|
|
42
52
|
def song_info=(v)
|
|
43
53
|
@position = v[:position].freeze
|
|
44
54
|
@title = v[:title].freeze
|
|
55
|
+
@length = v[:length].to_f
|
|
45
56
|
end
|
|
46
57
|
|
|
47
58
|
def elapsed=(v)
|
|
59
|
+
@elapsed_seconds = v
|
|
48
60
|
@indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
|
|
49
61
|
@paused = false
|
|
50
62
|
@changed = true
|
|
@@ -61,6 +73,20 @@ module MikePlayer
|
|
|
61
73
|
def display!(elapsed_info, countdown = nil)
|
|
62
74
|
return unless changed?
|
|
63
75
|
|
|
76
|
+
if @fullscreen
|
|
77
|
+
display_panel!(elapsed_info, countdown)
|
|
78
|
+
else
|
|
79
|
+
display_line!(elapsed_info, countdown)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def changed?
|
|
84
|
+
true == @changed
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def display_line!(elapsed_info, countdown)
|
|
64
90
|
mindicator = "(#{countdown}↓) " if countdown
|
|
65
91
|
|
|
66
92
|
position = colorize(@position, DIM_COLOR)
|
|
@@ -82,11 +108,36 @@ module MikePlayer
|
|
|
82
108
|
$stdout.flush
|
|
83
109
|
end
|
|
84
110
|
|
|
85
|
-
def
|
|
86
|
-
|
|
111
|
+
def display_panel!(elapsed_info, countdown)
|
|
112
|
+
mindicator = "(#{countdown}↓) " if countdown
|
|
113
|
+
count = countdown ? colorize(mindicator, COUNTDOWN_COLOR) : ''
|
|
114
|
+
state = colorize(@paused ? 'PAUSED' : 'PLAYING', @paused ? PAUSE_COLOR : PLAY_COLOR)
|
|
115
|
+
|
|
116
|
+
move_to(TITLE_ROW)
|
|
117
|
+
print("Playing #{colorize(@position, DIM_COLOR)}: #{colorize(@title, TITLE_COLOR)}")
|
|
118
|
+
|
|
119
|
+
move_to(BAR_ROW)
|
|
120
|
+
print("#{progress_bar} #{colorize(elapsed_info, ELAPSED_COLOR)} #{count}#{state}")
|
|
121
|
+
|
|
122
|
+
move_to(HINT_ROW)
|
|
123
|
+
print(colorize(HINT_TEXT, DIM_COLOR))
|
|
124
|
+
|
|
125
|
+
@changed = false
|
|
126
|
+
|
|
127
|
+
$stdout.flush
|
|
87
128
|
end
|
|
88
129
|
|
|
89
|
-
|
|
130
|
+
def move_to(row)
|
|
131
|
+
print("\e[#{row};1H\e[2K")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def progress_bar
|
|
135
|
+
pct = @length.positive? ? (@elapsed_seconds.to_f / @length).clamp(0, 1) : 0
|
|
136
|
+
filled = (pct * PROGRESS_WIDTH).round
|
|
137
|
+
bar = "[#{'#' * filled}#{'-' * (PROGRESS_WIDTH - filled)}]"
|
|
138
|
+
|
|
139
|
+
colorize(bar, @paused ? PAUSE_COLOR : PLAY_COLOR)
|
|
140
|
+
end
|
|
90
141
|
|
|
91
142
|
def colorize(text, color)
|
|
92
143
|
return text unless @color
|
data/lib/mikeplayer/playlist.rb
CHANGED
|
@@ -69,8 +69,9 @@ module MikePlayer
|
|
|
69
69
|
|
|
70
70
|
def song_info(i)
|
|
71
71
|
song_i_str = "#{i + 1}".rjust(self.size.to_s.size)
|
|
72
|
+
song = get(i)
|
|
72
73
|
|
|
73
|
-
return { position: "(#{song_i_str}/#{self.size})", title:
|
|
74
|
+
return { position: "(#{song_i_str}/#{self.size})", title: song.info, length: song.length }
|
|
74
75
|
end
|
|
75
76
|
|
|
76
77
|
def size
|
data/lib/mikeplayer/version.rb
CHANGED
data/lib/mikeplayer.rb
CHANGED
|
@@ -64,7 +64,7 @@ module MikePlayer
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
@thread = Thread.new do
|
|
67
|
-
@display = Display.new
|
|
67
|
+
@display = Display.new(fullscreen: @settings.fullscreen?)
|
|
68
68
|
@song_i = 0
|
|
69
69
|
|
|
70
70
|
while (@song_i < @playlist.size)
|
|
@@ -84,14 +84,14 @@ module MikePlayer
|
|
|
84
84
|
sleep(sleep_time)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
if
|
|
88
|
-
next_song
|
|
89
|
-
elsif paused?
|
|
87
|
+
if @player.paused?
|
|
90
88
|
@display.display!(song.length_str(@player.elapsed), minutes_remaining)
|
|
91
89
|
|
|
92
90
|
while paused?
|
|
93
91
|
sleep(sleep_time)
|
|
94
92
|
end
|
|
93
|
+
elsif playing?
|
|
94
|
+
next_song
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|