Class: Rtui::Progress
- Inherits:
-
Object
- Object
- Rtui::Progress
- Defined in:
- lib/rtui/progress.rb
Overview
Progress indicators
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #clear ⇒ Object
-
#components=(arguments) ⇒ Object
def format= (format) @format = format end.
- #file_transfer_mode ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #halt ⇒ Object
- #inc(step = 1) ⇒ Object
-
#initialize(title, total, *options) ⇒ Progress
constructor
Initializes a progress indicator.
- #inspect ⇒ Object
- #set(count) ⇒ Object
- #subject=(subject) ⇒ Object
Constructor Details
#initialize(title, total, *options) ⇒ Progress
Initializes a progress indicator.
Examples:
Just a bar and ETA: Rtui::Progress.new(“Foo”, 10, { :components => [:bar, :stat]})
A Spinner with just percentage: Rtui::Progress.new(“Foo”, 10, { :components => [:spinner, :percentage]})
Options:
-
bar => “=”
-
out => STDERR
Components:
-
title
-
spinner
-
percentage
-
stat
-
bar
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rtui/progress.rb', line 55 def initialize (title, total, *) = .first || {} @title = title @total = total @terminal_width = 80 @current = 0 @previous = 0 @finished = false @start_time = Time.now @previous_time = @start_time @title_width = 14 @subject = "" @out = [:out] || STDERR @bar_mark = [:bar] || "=" @colors = [:colors] || false @components = [:components] || [:title, :percentage, :bar, :stat] clear show end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
28 29 30 |
# File 'lib/rtui/progress.rb', line 28 def current @current end |
#start_time ⇒ Object
Returns the value of attribute start_time.
30 31 32 |
# File 'lib/rtui/progress.rb', line 30 def start_time @start_time end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
27 28 29 |
# File 'lib/rtui/progress.rb', line 27 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
29 30 31 |
# File 'lib/rtui/progress.rb', line 29 def total @total end |
Instance Method Details
#clear ⇒ Object
77 78 79 |
# File 'lib/rtui/progress.rb', line 77 def clear @out.print "\r#{(" " * (get_width - 1))}\r" end |
#components=(arguments) ⇒ Object
def format= (format)
@format = format
end
100 101 102 |
# File 'lib/rtui/progress.rb', line 100 def components= (arguments) @components = arguments end |
#file_transfer_mode ⇒ Object
91 92 93 94 |
# File 'lib/rtui/progress.rb', line 91 def file_transfer_mode return unless @components.index(:stat) @components[@components.index(:stat)] = :stat_for_file_transfer end |
#finish ⇒ Object
81 82 83 84 85 |
# File 'lib/rtui/progress.rb', line 81 def finish @current = @total @finished = true show end |
#finished? ⇒ Boolean
87 88 89 |
# File 'lib/rtui/progress.rb', line 87 def finished? @finished end |
#halt ⇒ Object
108 109 110 111 |
# File 'lib/rtui/progress.rb', line 108 def halt @finished = true show end |
#inc(step = 1) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/rtui/progress.rb', line 113 def inc step = 1 @current += step @current = @total if @current > @total show_if_needed @previous = @current end |
#inspect ⇒ Object
129 130 131 |
# File 'lib/rtui/progress.rb', line 129 def inspect "#<Rtui::Progress:#{@current}/#{@total}>" end |
#set(count) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/rtui/progress.rb', line 120 def set (count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |
#subject=(subject) ⇒ Object
104 105 106 |
# File 'lib/rtui/progress.rb', line 104 def subject=(subject) @subject = subject end |