Class: ProgressBar::Console

Inherits:
Base
  • Object
show all
Defined in:
lib/progress-bar.rb

Instance Attribute Summary

Attributes inherited from Base

#error, #i, #max, #start, #text

Instance Method Summary collapse

Methods inherited from Base

#done_dur, #done_rel, #increment!, #total_dur

Constructor Details

#initialize(*a) ⇒ Console

Returns a new instance of Console.



60
61
62
63
# File 'lib/progress-bar.rb', line 60

def initialize *a
	super *a
	change_text
end

Instance Method Details

#change_errorObject



82
83
84
85
# File 'lib/progress-bar.rb', line 82

def change_error
	STDERR.printf "\r\e[J%s\n", error
	change_text
end

#change_textObject Also known as: change_progress



73
74
75
76
77
78
79
# File 'lib/progress-bar.rb', line 73

def change_text
	l = [[100.0*i/max, 0].max, 100].min.to_i
	dd, td = done_dur, total_dur
	b = ?= * l
	b[-1] = ?>  unless 0 == l or 100 == l
	STDOUT.printf "\r\e[J%s / %s [%-*s] %s", format_time(dd), format_time(td), 100, b, text
end

#finishObject



87
88
89
# File 'lib/progress-bar.rb', line 87

def finish
	STDERR.puts
end

#format_time(t) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/progress-bar.rb', line 65

def format_time t
	if t.finite?
		sprintf "%02d:%02d:%02d", t/3600, t/60 % 3600, t % 60
	else
		"--:--:--"
	end
end