forked from erhanbas/navigator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprogress_bar_object.m
34 lines (32 loc) · 1.14 KB
/
progress_bar_object.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
classdef progress_bar_object < handle
properties
n_
percent_as_displayed_last_
did_print_at_least_one_line_
end
methods
function self = progress_bar_object(n)
self.n_ = n ;
self.percent_as_displayed_last_ = [] ;
self.did_print_at_least_one_line_ = false ;
end
function update(self, i)
n =self.n_ ;
percent = 100*(i/n) ;
percent_as_displayed = round(percent*10)/10 ;
if ~isequal(percent_as_displayed, self.percent_as_displayed_last_) ,
if self.did_print_at_least_one_line_ ,
delete_bar = repmat('\b', [1 1+50+1+2+4+1]) ;
fprintf(delete_bar) ;
end
bar = repmat('*', [round(percent/2) 1]) ;
fprintf('[%-50s]: %4.1f%%', bar, percent_as_displayed) ;
self.did_print_at_least_one_line_ = true ;
if i==n ,
fprintf('\n') ;
end
end
self.percent_as_displayed_last_ = percent_as_displayed ;
end
end
end