Code: Select all
call :progbar "command"
Thank you!
Moderator: DosItHelp
Code: Select all
call :progbar "command"
I don't see it as being practical or possible to make a progress bar for any command, as each commands execution time is essentially unknown.AR Coding wrote: ↑31 May 2021 15:15Hi, ive seen this, viewtopic.php?p=17719#p17719 but is there a way to make a progress bar with any command? I dont know where to put the code. Maybe someone can make something like:But i would appreciate anything that works.Code: Select all
call :progbar "command"
Thank you!
A barebones example, that should give you a good starting point:
Code: Select all
@Echo off
If not "%~1" == "" Goto %1
Cls
:# macros for launch and termination of 2nd thread via start / stop flag written to alternate data stream.
Set "Start.Thread.2=(Powershell -c "remove-item -path '%~nx0' -Stream 'Status'") 2> nul & Echo(Loading&((Echo(1)>"%~f0:Status") & Start /b "" "%~f0" Thread2"
Set "End.Thread.2=((Echo(0)>"%~f0:Status")&Echo("
%Start.Thread.2%
For /l %%i in (1 1 200000)Do Set var=%%i
%End.Thread.2%
Echo(%var%
Pause
Goto :Eof
:Thread2
:# Check completion status flagged in status stream of this file. Exit on 0 flag [stopped].
(More < "%~f0:Status" 2> nul) | findstr /LIC:"0" > nul && Exit
:# Basic animation. modify to suit your needs.
<nul Set /p "=."
:# Subsecond delay. ~ 1/60th of a second
For /L %%i in (1 1 800)Do (
(Call )
)
Goto :Thread2
animation is actioned in
Code: Select all
:thread2
Code: Select all
<nul set /p "=."
Code: Select all
:# Basic animation. modify to suit your needs.
<nul Set /p "=."
Code: Select all
@Echo off
:# Used to jump to Thread2 on relaunch
If /I "%~1" == "Thread2" Goto %1
Cls
:# Define Escape character for Virtual terminal sequences
For /f "Delims=" %%e in ('Echo(Prompt $E^|Cmd')Do Set "\E=%%e"
:# macros for launch and termination of 2nd thread via start / stop flag written to alternate data stream.
:#------------------
:# Start.Thread.2 - Remove status thread from this file if present;
:# Notify command has started;
:# Flag status 1 in Stream :status;
:# Use start /b with params to relaunch this script and execute second thread
Set "Start.Thread.2=(Powershell -c "remove-item -path '%~nx0' -Stream 'Status'") 2> nul & Echo(Executing&((Echo(1)>"%~f0:Status") & Start /high /b "" "%~f0" Thread2"
:#------------------
:# End.Thread.2 - Flag status 0 in Stream :Status;
:# Execute a small delay to ensure thread two has time to emit linefeed and enable cursor display.
Set "End.Thread.2=((Echo(0)>"%~f0:Status")&For /L %%i in (1 1 750)Do ((Call ))"
Mode 160
For /f "Tokens=2 delims=: " %%G in ('Mode^|findstr /lic:"Columns"')Do Set "Columns=%%G"
%Start.Thread.2% + 200
For /l %%i in (1 1 200000)Do Set var=%%i
%End.Thread.2%
Echo([%var%] iterations actioned.
Pause
Goto :Eof
:Thread2
If not "%~3" == "" ( Set "Delay[i]=%~3" )Else Set "Delay[i]=800"
<nul Set /p "=%\E%7%\E%[?25l"
Set "T2[i]=0"
Set "T2[c]=160"
:T2.Loop
Set /A T2[i]+=1,T2[c]+=1
:# Check completion status flagged in status stream of this file.
(More < "%~f0:Status" 2> nul) | findstr /LIC:"0" > nul && (<nul Set /P "=%\E%[?25h%\E%[1E"& Exit)
:# Basic animation. modify to suit your needs.
<nul Set /p "=%\E%8%\E%[3%T2[i]%m%~2%\E%[0m%\E%7"
If %T2[i]% EQU 7 Set "T2[i]=0"
If %T2[c]% GEQ %Columns% (Set "T2[c]=0" & <nul Set /P "=%\E%[1G%\E%7%\E%[K")
Goto :T2.Loop
Code: Select all
%Start.Thread.2% + 200
the '+' is the character output r the loading bar, the '200' is redundant from an alternate version that took a numeric parameter to base a delay on.AR Coding wrote: ↑02 Jun 2021 08:16What does the + 200 do inSorry if im asking to many questions , im just not very good at thisCode: Select all
%Start.Thread.2% + 200
Code: Select all
:# Author: T3RRY Created: 03/06/2021
:# Purpose: RGB Spinner animation for load / waiting indication while script continues to run.
:# Utilises a second thread to display animation while the main script continues executing.
:# Execution and termination of the thread is controlled using a value stored in an alternate data
:# stream of this file:. 1 = run ; 0 = stop
@Echo off & CD /D "%~dp0"
======:# Runs Thread on relaunch
If /I "%~1" == "Thread" Goto %1
Cls
====================:# OS Requirement tests
:# Verify NTFS drive
(Echo(verify.NTFS >"%~f0:Status") || (Echo(This file must be located on an NTFS drive as it utilises alternate data streams.&Exit /B 1)
=========================:# Windows Version control.
Set "Win10="
Ver | Findstr /LIC:" 10." > nul && Set "Win10=true"
============================:# Test if virtual terminal codes enabled ; enable if false
:# removes win10 flag definition if version does not support Virtual Terminal sequences
If defined Win10 (
Reg Query HKCU\Console | %SystemRoot%\System32\findstr.exe /LIC:"VirtualTerminalLevel REG_DWORD 0x1" > nul || (
Reg Add HKCU\Console /f /v VirtualTerminalLevel /t REG_DWORD /d 1
) > Nul || Set "Win10="
)
If not defined Win10 (
Echo(Virtual terminal sequences not supported on your system
Exit /B 1
)
=====:# Define Escape character for Virtual terminal sequences
For /f "Delims=" %%e in ('Echo(Prompt $E^|Cmd')Do Set "\E=%%e"
==================:# macros start and stop Thread via t/f flag written to alternate data stream.
:# Start.Thread - Save current Codepage;
:# Remove status thread from this file if present;
:# Notify command has started;
:# Flag status 1 in Stream :status;
:# Use start /b with params to relaunch this script and execute second thread
Set "Start.Thread=(For /F "tokens=2 Delims=:" %%G in ('CHCP')Do Set "restore.CP=CHCP %%G")&((Echo(1)>"%~f0:Stream") & Start /AboveNormal /b "executing." "%~f0" Thread"
:# End.Thread - Flag status 0 in Stream :Status;
:# Execute a small delay to ensure thread two has time to enable cursor display and clear animation.
:# [Delay of approx. 1/66th of a second]
Set "End.Thread=((Echo(0)>"%~f0:Stream")&For /L %%i in (1 1 750)Do ((Call ))"
===:# Usage Examples. Multiple examples used to show thread is suitable for use with
:# commands of any execution time.
:# Example of running RGB spinner animation while another command executes.
:# NOTE: Commands with output must be redirected to a stream or file
:# and output using more or type AFTER using the End.Thread macro
:# as the spinner animation moves the cursor and console output that
:# occurs during spinner animation will displace and be displaced by the animation.
%Start.Thread% Example 1
For /l %%i in (1 1 100000)Do Set "var=%%i"
%End.Thread%
Echo([%var%] iterations actioned.
%Start.Thread% Example 2
For /l %%i in (1 1 10000)Do Set "var=%%i"
%End.Thread%
Echo([%var%] iterations actioned.
%Start.Thread% Example 3
Set "var=1"
%End.Thread%
Echo([%var%] iterations actioned.
======================================:# End script cleanup
Powershell -c "remove-item -path '%~nx0' -Stream '*'"
@Pause
Goto :Eof
===========================================================
:Thread - Animation; RGB spinner
:# NOTE - Multiple instances of this thread can not be run in parallel;
:# as Virtual terminal Cursor save operation will overide information stored by parallel threads
Set ^"Params=%*"
Setlocal EnableDelayedExpansion
Set "Params=!Params:%~1 =!"
TITLE !Params!
CHCP 65001 > nul
<nul set /p "=%\E%[1EExecuting:%\E%[36m !Params!%\E%[0m%\E%[?25l%\E%[1E%\E%7"
Set "T2[L]=0" %= Rem Spinner Loop count =%
Set "T2[chars]= |/-\" %= Rem Spinner characters =%
Set "Delay=5" %= Framerate in Centiseconds =%
:# frame control via elapsed time by Dave Benham - https://www.dostips.com/forum/viewtopic.php?f=3&t=4741
For /l %%. in ()Do (
%= Check completion status flagged in status stream of this file; =%
(For /F "UsebackQ Delims=" %%G in ("%~f0:Stream")Do if %%G EQU 0 (
<nul Set /P "=%\E%[?25h%\E%8%\E[K%" %= restore cursor =%
%restore.CP% > nul %= restore codepage =%
<nul Set /P "=%\E%[7;32m!Params! Complete.%\E%[0m%\E%[1E%\E%[M%\E%[K" %= notify completion; Emit newline; Delete last line of animation =%
(TITLE )
Exit %= exit thread =%
))2> nul
%= Calculate time elapsed =%
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
if !tDiff! lss 0 set /a tDiff+=24*60*60*100
if !tDiff! geq !delay! (
%= delay has expired ; display frame =%
Set /A T2[L]+=1 %= Increment index point of spinner string =%
%= Output Spinner frame. Overwites previous output using saved cursor position =%
For /f "Delims=" %%v in ("!T2[L]!")Do <nul Set /p "=%\E%8%\E%[38;2;20;20;20;7m%\E%[48;2;150;;150m╔═╗╔═╗╔═╗%\E%[0;38;2;150;;150m%\E%[K%\E%[E║%\E%[38;2;20;20;20;7m%\E%[48;2;255;;m!T2[chars]:~%%v,1!%\E%[0m%\E%[38;2;20;20;20;7m%\E%[48;2;150;;150m║║%\E%[38;2;20;20;20;7m%\E%[48;2;;255;m!T2[chars]:~%%v,1!%\E%[0m%\E%[38;2;20;20;20;7m%\E%[48;2;150;;150m║║%\E%[38;2;20;20;20;7m%\E%[48;2;;100;255m!T2[chars]:~%%v,1!%\E%[0m%\E%[38;2;20;20;20;7m%\E%[48;2;150;;150m║%\E%[0m%\E%[K%\E%[E%\E%[38;2;20;20;20;7m%\E%[48;2;150;;150m╚═╝╚═╝╚═╝%\E%[0m%\E%[K%\E%[1G%\E%[2A%\E%7"
If !T2[L]! EQU 4 Set "T2[L]=0" %= Reset index point of spinner string =%
set /a t1=t2
)
)