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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rtui/progress.rb', line 47 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] || STDOUT @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.
20 21 22 |
# File 'lib/rtui/progress.rb', line 20 def current @current end |
#start_time ⇒ Object
Returns the value of attribute start_time.
22 23 24 |
# File 'lib/rtui/progress.rb', line 22 def start_time @start_time end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
19 20 21 |
# File 'lib/rtui/progress.rb', line 19 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
21 22 23 |
# File 'lib/rtui/progress.rb', line 21 def total @total end |
Instance Method Details
#clear ⇒ Object
69 70 71 |
# File 'lib/rtui/progress.rb', line 69 def clear @out.print "\r#{(" " * (TTY.get_width - 1))}\r" end |
#components=(arguments) ⇒ Object
def format= (format)
@format = format
end
92 93 94 |
# File 'lib/rtui/progress.rb', line 92 def components= (arguments) @components = arguments end |
#file_transfer_mode ⇒ Object
83 84 85 86 |
# File 'lib/rtui/progress.rb', line 83 def file_transfer_mode return unless @components.index(:stat) @components[@components.index(:stat)] = :stat_for_file_transfer end |
#finish ⇒ Object
73 74 75 76 77 |
# File 'lib/rtui/progress.rb', line 73 def finish @current = @total @finished = true show end |
#finished? ⇒ Boolean
79 80 81 |
# File 'lib/rtui/progress.rb', line 79 def finished? @finished end |
#halt ⇒ Object
100 101 102 103 |
# File 'lib/rtui/progress.rb', line 100 def halt @finished = true show end |
#inc(step = 1) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/rtui/progress.rb', line 105 def inc step = 1 @current += step @current = @total if @current > @total show_if_needed @previous = @current end |
#inspect ⇒ Object
121 122 123 |
# File 'lib/rtui/progress.rb', line 121 def inspect "#<RTUI::Progress:#{@current}/#{@total}>" end |
#set(count) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/rtui/progress.rb', line 112 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
96 97 98 |
# File 'lib/rtui/progress.rb', line 96 def subject=(subject) @subject = subject end |