mikeplayer 1.1.2 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75710f4741268d6bbc3c8708b626733ac02bf3dbbcaf3c8224761ddaea270ca4
4
- data.tar.gz: 75fff78aa2ebfa4b4a2815a743fca6a923a4f85ee9bddf25f528167b08cdfaf0
3
+ metadata.gz: b38d5b7fef4b5141b1f884d386ca6d8cbc17b4890aacaac2a649b06aefd84674
4
+ data.tar.gz: 1f38509a5e275b35d9adbb83c4cf09b23c739f999afe71c7d8ffc16ffbd865d6
5
5
  SHA512:
6
- metadata.gz: 8d20411df67b44cd5f25b4aaea1b1ab22e632eaa8505a47c3fbee652e88e75e314e42785e525cfbb97bf71876fdf4300165248d90deb0bfeaf9be1eeba459e06
7
- data.tar.gz: a2877632fb5b48cb60d1eec6502f8b3d5015384c952852a47d6aace6531690b6adee4d66851e07ec29bf040d3b69139bdd5ca5d95bb4cc20c2d28ae66fbb65c2
6
+ metadata.gz: 0216f0b2f19389ce060bd48fb1ce7bbfbd13a8e9ff3ae461c16830b745c5eaa463e9f4f1c6706e2085338cc44848d11b855e32e0454a98e5f8cdd96ec916939c
7
+ data.tar.gz: a72f9a0446bcc94e87229812029b7de95bfb1d881450d665fce45e8161c0aa9ee83c762bf42d392e08491e68f10c03244819efa8e94499725d767c7be6f02338
data/bin/MikePlayer.rb CHANGED
@@ -14,14 +14,15 @@ OptionParser.new do |opt|
14
14
 
15
15
  EOF
16
16
  opt.on('-s', '--shuffle', 'Shuffle playlist.') { |o| options[:shuffle] = true }
17
- opt.on('-r', '--random n', 'Create playlist with randomly picked n songs.') { |o| options[:random] = o.to_i }
17
+ opt.on('-r', '--random n', Integer, 'Create playlist with randomly picked n songs.') { |o| options[:random] = o }
18
18
  opt.on('-o', '--overwrite', 'Overwrite playlist.') { |o| options[:overwrite] = true }
19
- opt.on('-v', '--volume n', 'Changes default volume.') { |o| options[:volume] = o }
19
+ opt.on('-v', '--volume n', Float, 'Changes default volume.') { |o| options[:volume] = o }
20
20
  opt.on('-p', '--playlist name', 'Play playlist name.') { |o| options[:playlist] = o }
21
21
  opt.on('-l', '--list', 'List songs in playlist.') { |o| options[:list] = true; }
22
22
  opt.on('-d', '--directory name', 'Directory to find mp3s.') { |o| options[:directory] = o }
23
- opt.on('-t', '--time minutes', 'Limit time to number of minutes.') { |o| options[:minutes] = o }
23
+ opt.on('-t', '--time minutes', Integer, 'Limit time to number of minutes.') { |o| options[:minutes] = o }
24
24
  opt.on('-x', '--debug', 'Turn on debug.') { |o| options[:debug] = true }
25
+ opt.on('-f', '--fullscreen', 'Use an alternate full-screen buffer while playing.') { |o| options[:fullscreen] = true }
25
26
  end.parse!
26
27
 
27
28
  MikePlayer::Player.new(options, ARGV).play
@@ -3,24 +3,57 @@ module MikePlayer
3
3
  PAUSE_INDICATOR = '||'.freeze
4
4
  INDICATOR_SIZE = 4
5
5
 
6
+ RESET = "\e[0m".freeze
7
+ TITLE_COLOR = "\e[1;36m".freeze # bold cyan
8
+ DIM_COLOR = "\e[2m".freeze # dim gray
9
+ BANNER_COLOR = "\e[1;37m".freeze # bold white
10
+ ELAPSED_COLOR = "\e[37m".freeze # white
11
+ COUNTDOWN_COLOR = "\e[33m".freeze # yellow
12
+ PLAY_COLOR = "\e[32m".freeze # green
13
+ PAUSE_COLOR = "\e[1;31m".freeze # bold red
14
+
15
+ ENTER_ALT_SCREEN = "\e[?1049h\e[2J\e[H".freeze
16
+ EXIT_ALT_SCREEN = "\e[?1049l".freeze
17
+
18
+ def self.colorize(text, color)
19
+ return text unless $stdout.tty?
20
+
21
+ "#{color}#{text}#{RESET}"
22
+ end
23
+
24
+ def self.enter_fullscreen
25
+ print(ENTER_ALT_SCREEN)
26
+ $stdout.flush
27
+ end
28
+
29
+ def self.exit_fullscreen
30
+ print(EXIT_ALT_SCREEN)
31
+ $stdout.flush
32
+ end
33
+
6
34
  def initialize
7
35
  @width = 0
8
36
  @indicator = ''
37
+ @paused = false
9
38
  @changed = false
39
+ @color = $stdout.tty?
10
40
  end
11
41
 
12
42
  def song_info=(v)
13
- @info_prefix = "\r#{v}".freeze
43
+ @position = v[:position].freeze
44
+ @title = v[:title].freeze
14
45
  end
15
46
 
16
47
  def elapsed=(v)
17
48
  @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
49
+ @paused = false
18
50
  @changed = true
19
51
  end
20
52
 
21
53
  def paused
22
- if (false == @indicator.include?(PAUSE_INDICATOR))
54
+ if (false == @paused)
23
55
  @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE)
56
+ @paused = true
24
57
  @changed = true
25
58
  end
26
59
  end
@@ -30,13 +63,20 @@ module MikePlayer
30
63
 
31
64
  mindicator = "(#{countdown}↓) " if countdown
32
65
 
33
- print("\r" << ' '.ljust(@width))
66
+ position = colorize(@position, DIM_COLOR)
67
+ title = colorize(@title, TITLE_COLOR)
68
+ elapsed = colorize(elapsed_info, ELAPSED_COLOR)
69
+ indicator = colorize(@indicator, @paused ? PAUSE_COLOR : PLAY_COLOR)
70
+ count = countdown ? colorize(mindicator, COUNTDOWN_COLOR) : ''
34
71
 
35
- info = "#{@info_prefix} #{elapsed_info} #{mindicator}#{@indicator}"
72
+ plain_info = "Playing #{@position}: #{@title} #{elapsed_info} #{mindicator}#{@indicator}"
73
+ info = "\rPlaying #{position}: #{title} #{elapsed} #{count}#{indicator}"
74
+
75
+ print("\r" << ' '.ljust(@width))
36
76
 
37
77
  print(info)
38
78
 
39
- @width = info.size
79
+ @width = plain_info.size
40
80
  @changed = false
41
81
 
42
82
  $stdout.flush
@@ -45,5 +85,13 @@ module MikePlayer
45
85
  def changed?
46
86
  true == @changed
47
87
  end
88
+
89
+ private
90
+
91
+ def colorize(text, color)
92
+ return text unless @color
93
+
94
+ "#{color}#{text}#{RESET}"
95
+ end
48
96
  end
49
97
  end
@@ -70,7 +70,7 @@ module MikePlayer
70
70
  def song_info(i)
71
71
  song_i_str = "#{i + 1}".rjust(self.size.to_s.size)
72
72
 
73
- return "Playing (#{song_i_str}/#{self.size}): #{get(i).info}".freeze
73
+ return { position: "(#{song_i_str}/#{self.size})", title: get(i).info }
74
74
  end
75
75
 
76
76
  def size
@@ -16,8 +16,9 @@ module MikePlayer
16
16
  @music_dir = options[:directory] || File.join(@home, DEFAULT_DIRECTORY)
17
17
  @settings_dir = options[:settings] || File.join(@home, SETTINGS_DIRECTORY)
18
18
  @minutes = options[:minutes].to_i
19
- @debug = options[:debug]
20
- @random = options[:random].to_i
19
+ @debug = options[:debug]
20
+ @random = options[:random].to_i
21
+ @fullscreen = options[:fullscreen]
21
22
 
22
23
  if (false == Dir.exist?(@settings_dir))
23
24
  Dir.mkdir(@settings_dir)
@@ -48,6 +49,10 @@ module MikePlayer
48
49
  return true == @list
49
50
  end
50
51
 
52
+ def fullscreen?
53
+ return true == @fullscreen
54
+ end
55
+
51
56
  private
52
57
 
53
58
  def find_playlist(user_option)
@@ -1,3 +1,3 @@
1
1
  module MikePlayer
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/mikeplayer.rb CHANGED
@@ -49,8 +49,13 @@ module MikePlayer
49
49
  def play
50
50
  @playlist.shuffle! if @settings.shuffle?
51
51
 
52
- puts "Mike Player v#{MikePlayer::VERSION}"
53
- puts "Playlist #{@playlist.info}\n"
52
+ if @settings.fullscreen?
53
+ Display.enter_fullscreen
54
+ at_exit { Display.exit_fullscreen }
55
+ end
56
+
57
+ puts Display.colorize("Mike Player v#{MikePlayer::VERSION}", Display::BANNER_COLOR)
58
+ puts "#{Display.colorize("Playlist #{@playlist.info}", Display::DIM_COLOR)}\n"
54
59
 
55
60
  if (0 == @playlist.size)
56
61
  puts "No songs in playlist."
@@ -82,6 +87,8 @@ module MikePlayer
82
87
  if playing? && @player.stopped?
83
88
  next_song
84
89
  elsif paused?
90
+ @display.display!(song.length_str(@player.elapsed), minutes_remaining)
91
+
85
92
  while paused?
86
93
  sleep(sleep_time)
87
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikeplayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Crockett