Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit d810b0e4da02eafcda6bbd568b398b237d5e9bbf Ivan Garmatenko committed Feb 22, 2012
Showing with 79 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +4 −0 Gemfile
  3. +1 −0 Rakefile
  4. +44 −0 lib/shell-spinner.rb
  5. +3 −0 lib/shell-spinner/version.rb
  6. +22 −0 shell-spinner.gemspec
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+.idea
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in shell-spinner.gemspec
+gemspec
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,44 @@
+require "shell-spinner/version"
+
+module ShellSpinner
+
+ def self.wrap text = nil, &block
+ with_message text do
+ join_spinner_thread(block)
+ end
+ end
+
+ private
+
+ def self.with_message text = nil
+ require 'colorize'
+
+ begin
+ print "#{text}... " unless text.nil?
+ yield
+ print "done\n".colorize(:green) unless text.nil?
+ rescue Exception => e
+ print "fail\n".colorize(:red) unless text.nil?
+ raise e
+ end
+ end
+
+ def self.join_spinner_thread proc
+ chars = %w{ | / - \\ }
+ thread = Thread.new { proc.call }
+
+ while thread.alive?
+ print chars[0]
+ sleep 0.1
+ print "\b"
+
+ chars.push chars.shift
+ end
+
+ thread.join
+ end
+end
+
+def ShellSpinner text = nil, &block
+ ShellSpinner.wrap text, &block
+end
@@ -0,0 +1,3 @@
+module ShellSpinner
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "shell-spinner/version"
+
+Gem::Specification.new do |s|
+ s.name = "shell-spinner"
+ s.version = ShellSpinner::VERSION
+ s.authors = ["Ivan Garmatenko"]
+ s.email = %w(cheef.che@gmail.ru)
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "shell-spinner"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_runtime_dependency "colorize"
+end

0 comments on commit d810b0e

Please sign in to comment.