Skip to content

Commit

Permalink
Merge pull request #31 from hermes-logicalbricks/master
Browse files Browse the repository at this point in the history
Now work in Linux with mpg123 too
  • Loading branch information
mattsears committed Oct 6, 2012
2 parents e6c6e6d + 68808a9 commit 95cdc24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -73,7 +73,7 @@ Make sure your .rspec file in your application's root directory contains the fol

Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by the Nyan Cat song by default!

**This currently only works on Mac OS X or on Linux (if you have mpg321 installed).**
**This currently only works on Mac OS X or on Linux (if you have mpg321 or mpg123 installed).**

Contributing
----------
Expand Down
17 changes: 15 additions & 2 deletions lib/nyan_cat_music_formatter.rb
Expand Up @@ -33,13 +33,26 @@ def nyan_mp3
def start input
super
kernel.system("afplay #{nyan_mp3} &") if osx?
kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if linux?
play_on_linux if linux?
end

def kill_music
if File.exists? nyan_mp3
system("killall -9 afplay &>/dev/null") if osx?
system("killall -9 mpg321 &>/dev/null") if linux?
kill_music_on_linux if linux?
end
end

private

def play_on_linux
kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg321 &>/dev/null && type mpg321 &>/dev/null')
kernel.system("[ -e #{nyan_mp3} ] && type mpg123 &>/dev/null && mpg123 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg123 &>/dev/null && type mpg123 &>/dev/null')
end

def kill_music_on_linux
system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
end

end
1 change: 1 addition & 0 deletions spec/nyan_cat_music_formatter_spec.rb
Expand Up @@ -69,6 +69,7 @@ def seen
it 'plays the song for linux too' do
formatter.start 10
mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} &>/dev/null &" }.should be
end
end

Expand Down

0 comments on commit 95cdc24

Please sign in to comment.