README. class Progress -> ProgressBar

master
Denis Knauf 2014-12-23 18:19:55 +01:00
parent 76b0870cde
commit 15f7c841f2
3 changed files with 38 additions and 22 deletions

23
README.md Normal file
View File

@ -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.

View File

@ -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.

View File

@ -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