-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors the text progress bar so it can be disabled when controls.d…
…isplay is off
- Loading branch information
1 parent
bf67b6f
commit cd005d8
Showing
8 changed files
with
68 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
function textProgressBar(curm,pct) | ||
|
||
persistent lastNchar | ||
|
||
strDotsMax = 40; | ||
|
||
if strcmpi(curm,'init') | ||
%fprintf('\n'); | ||
lastNchar = 0; | ||
return; | ||
end | ||
|
||
if strcmpi(curm,'end') | ||
fprintf('\n'); | ||
return; | ||
end | ||
|
||
if isempty(lastNchar) | ||
lastNchar = 0; | ||
end | ||
|
||
%curm = 'progress'; | ||
|
||
nDots = floor(pct * strDotsMax); | ||
progressmsg = ['[' repmat('*',1,nDots) repmat('.',1,strDotsMax-nDots) ']']; | ||
|
||
% progressmsg=[183-uint16((1:40)<=(pct*40)).*(183-'*') '']; | ||
% %curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); | ||
progressmsg=sprintf('\n %s %5.1f%% %s',curm,(pct*100),progressmsg); | ||
|
||
fprintf('%s%s',repmat(sprintf('\b'),1,lastNchar),progressmsg); | ||
drawnow | ||
lastNchar=length(progressmsg); | ||
|
||
function textProgressBar(curm, pct, varargin) | ||
% Draws a progress bar in the console. The inputs are the message (char array) and | ||
% percentage progress expressed as a decimal (i.e., between 0 and 1). | ||
% Optionally a boolean value can be provided to disable the progress | ||
% bar. | ||
% | ||
% textProgressBar("DREAM", 0.5, false) | ||
persistent lastNchar | ||
persistent display | ||
|
||
if ~isempty(varargin) | ||
display = varargin{1}; | ||
elseif isempty(display) | ||
display = true; | ||
end | ||
|
||
if ~display | ||
return; | ||
end | ||
|
||
strDotsMax = 40; | ||
|
||
if pct == 0 | ||
%fprintf('\n'); | ||
lastNchar = 0; | ||
return; | ||
end | ||
|
||
if lastNchar==0 && pct>=1 | ||
return | ||
end | ||
|
||
if isempty(lastNchar) | ||
lastNchar = 0; | ||
end | ||
|
||
nDots = floor(pct * strDotsMax); | ||
progressmsg = ['[' repmat('*',1,nDots) repmat('.',1,strDotsMax-nDots) ']']; | ||
|
||
progressmsg=sprintf('\n%s %5.1f%% %s',curm,fix(pct*1000)/10,progressmsg); | ||
|
||
fprintf('%s%s',repmat(sprintf('\b'),1,lastNchar),progressmsg); | ||
drawnow | ||
lastNchar=length(progressmsg); | ||
|
||
if pct == 1 | ||
fprintf('\n'); | ||
lastNchar = 0; | ||
return; | ||
end | ||
end |