diff --git a/README.md b/README.md new file mode 100644 index 0000000..9acdf2c --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +ProgressBar +=========== + +Usage +===== + +This example will use your Terminal, if possible. +If your program will be started without a Terminal, +it will use kdialog for display a window. + + pb = ProgressBar.new 100, 'Initial Text...' + pb.i += 5 + pb.inc! 5 + pb.text = 'Something different' + pb.inc! 20 + pb.text = 'Second phase' + pb.inc! 60 + pb.text = 'Last Steps' + pb.inc! 20 + pb.text = 'Done!' + +If you want to force to use kdialog use ProgressBar::KDialog.new or +if you want to use your Console, use ProgressBar::Console. diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index dedcd71..0000000 --- a/README.rdoc +++ /dev/null @@ -1,19 +0,0 @@ -= progress-bar - -Description goes here. - -== Contributing to progress-bar - -* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. -* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. -* Fork the project. -* Start a feature/bugfix branch. -* Commit and push until you are happy with your contribution. -* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. -* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. - -== Copyright - -Copyright (c) 2014 Denis Knauf. See LICENSE.txt for -further details. - diff --git a/lib/progress-bar.rb b/lib/progress-bar.rb index 9ec5d43..84ca7d0 100644 --- a/lib/progress-bar.rb +++ b/lib/progress-bar.rb @@ -1,6 +1,18 @@ require 'dbus' -class Progress +module ProgressBar + def self.new *a + if STDERR.tty? + Console.new *a + elsif 'KDE' == ENV['XDG_CURRENT_DESKTOP'] + KDialog.new *a + else + KDialog.new *a + end + end +end + +class ProgressBar::Base attr_reader :max, :i, :text, :error attr_accessor :start def initialize max = nil, text = nil @@ -38,7 +50,7 @@ class Progress def finish() end end -class ConsoleProgress < Progress +class ProgressBar::Console < ProgressBar::Base def initialize *a super *a change_text @@ -65,7 +77,7 @@ class ConsoleProgress < Progress end end -class KDialogProgress < Progress +class ProgressBar::KDialog < ProgressBar::Base attr_reader :dialog_service_path, :dialog_object_path, :errors, :dialog_object def initialize *a super *a