-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmdLineProgressBar.m
More file actions
36 lines (35 loc) · 977 Bytes
/
Copy pathCmdLineProgressBar.m
File metadata and controls
36 lines (35 loc) · 977 Bytes
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
35
36
classdef CmdLineProgressBar < handle
% class for command-line progress-bar notification.
% Use example:
% pb = CmdLineProgressBar('Doing stuff...');
% for k = 1 : 10
% pb.print(k,10)
% % do stuff
% end
%
% Author: Itamar Katz, itakatz@gmail.com
properties
last_msg_len = 0;
end
methods
%--- ctor
function obj = CmdLineProgressBar(msg)
fprintf('%s', msg)
end
%--- print method
function print(obj, n, tot)
fprintf('%s', char(8*ones(1, obj.last_msg_len))) % delete last info_str
info_str = sprintf('%d/%d', n, tot);
fprintf('%s', info_str);
%--- assume user counts monotonically
if n == tot
fprintf('\n')
end
obj.last_msg_len = length(info_str);
end
%--- dtor
function delete(obj)
fprintf('\n')
end
end
end