- Jun
- 22
- 0
To give the response of working to the user in batchfiles which have a longer execution time you can display a progressbar or a progresscounter. I have them in a file called "util.btm" and call them this way:
do i = 0 to 100
gosub "util" display_progressbar 0 %i 100
enddo
Here the scripts:
:progresscounter [start current end]
iff %end le %start then
set xxx=%end
set end=%start
set start=%xxx
unset xxx
endiff
if not %current ge %start .and. not %current le %end return 0
set total=%@eval[%end - %start]
set done=%@eval[%current - %start]
set progress=%@eval[%done / %@max[1,%total]]
return %@int[%@eval[%progress * 100]]
:display_progresscounter [start current end]
set sd1=%_expansion
setdos /x0
gosub progresscounter %start %current %end
set ret=%_?
setdos /a1
echos ^e[s %ret ^% ^e[u
setdos /a0
setdos /x-%sd1
return
:display_progressbar [start current end]
set len=75
set sd1=%_expansion
setdos /x0
gosub progresscounter %start %current %end
set ret=%_?
setdos /a1
echos ^e[s %@repeat[²,%@int[%@eval[%ret / 100 * %len]]]%@repeat[°,%@eval[%len - %@int[%@eval[%ret / 100 * %len]]]] ^e[u
setdos /a0
setdos /x-%sd1
return
Of course you can change the "len" variable as well as the two repeated bar-characters.
do i = 0 to 100
gosub "util" display_progressbar 0 %i 100
enddo
Here the scripts:
:progresscounter [start current end]
iff %end le %start then
set xxx=%end
set end=%start
set start=%xxx
unset xxx
endiff
if not %current ge %start .and. not %current le %end return 0
set total=%@eval[%end - %start]
set done=%@eval[%current - %start]
set progress=%@eval[%done / %@max[1,%total]]
return %@int[%@eval[%progress * 100]]
:display_progresscounter [start current end]
set sd1=%_expansion
setdos /x0
gosub progresscounter %start %current %end
set ret=%_?
setdos /a1
echos ^e[s %ret ^% ^e[u
setdos /a0
setdos /x-%sd1
return
:display_progressbar [start current end]
set len=75
set sd1=%_expansion
setdos /x0
gosub progresscounter %start %current %end
set ret=%_?
setdos /a1
echos ^e[s %@repeat[²,%@int[%@eval[%ret / 100 * %len]]]%@repeat[°,%@eval[%len - %@int[%@eval[%ret / 100 * %len]]]] ^e[u
setdos /a0
setdos /x-%sd1
return
Of course you can change the "len" variable as well as the two repeated bar-characters.