Animated loading screen
Posted: 16 Jun 2019 17:37
Any script witch contains loading animated script? I working on my program in batch and need some sort of loading screen...
Thanks!
Thanks!
Code: Select all
@echo off
for /l %%a in (1,1,100) do (
cls
echo Currently working: %%a...
)
echo done
pause
Code: Select all
@echo off
for /l %%a in (1,1,20) do (
cls
call set "bar=%%bar%%#"
call echo %%bar%%
ping localhost -n 1 >nul
)
echo done
pause
Code: Select all
@echo off &setlocal EnableDelayedExpansion
::main
call :start_spinner
set /a "n=0"
for /l %%i in (1 1 50000) do set /a "n+=1"
call :exit_spinner
echo %n%
pause
::spinner
exit /b
:start_spinner
if defined __spin__ goto spin
set "__spin__=1"
for %%i in (v2Forced vtEnabled cursorHide cursorShow colorYellow colorGreen colorRed colorReset) do set "%%i="
for /f "tokens=3" %%i in ('2^>nul reg query "HKCU\Console" /v "ForceV2"') do set /a "v2Forced=%%i"
if "!v2Forced!" neq "0" for /f "tokens=2 delims=[]" %%i in ('ver') do for /f "tokens=2-4 delims=. " %%j in ("%%i") do (
if %%j gtr 10 (
set "vtEnabled=1"
) else if %%j equ 10 (
if %%k gtr 0 (set "vtEnabled=1") else if %%l geq 10586 set "vtEnabled=1"
)
)
if defined vtEnabled (
for /f %%i in ('echo prompt $e^|cmd') do set "esc=%%i"
set "cursorHide=!esc![?25l" &set "cursorShow=!esc![?25h"&set "colorYellow=!esc![33m" &set "colorGreen=!esc![32m" &set "colorRed=!esc![31m" &set "colorReset=!esc![m"
)
for /f %%i in ('copy /z "%~f0" nul') do set "cr=%%i"
for /f %%i in ('echo prompt $h^|cmd') do set "bs=%%i"
>"%temp%\spinner.~tmp" type nul
start /b cmd /c ""%~fs0" spin"
exit /b
:exit_spinner
del "%temp%\spinner.~tmp"
set "__spin__="
>nul ping -n 1 localhost
echo(!cr! - - -!colorGreen! Ready !colorYellow!- - - !colorReset!!cursorShow!
echo(
exit /b
:spin
echo(!cursorHide!!colorYellow!
for /l %%i in () do for %%j in ("\ | / -" "| / - \" "/ - \ |" "- \ | /") do for /f "tokens=1-4" %%k in (%%j) do (
<nul set /p "=!bs!!cr! %%k %%l %%m!colorRed! Please wait . . . !colorYellow!%%l %%m %%n "
>nul ping -n 1 localhost
if not exist "%temp%\spinner.~tmp" exit
)
Code: Select all
@echo off
for /l %%a in (1,1,100) do echo|set /p="#"
echo.done.
pause>nul
that's pretty cool.aGerman wrote: ↑20 Jun 2019 12:59
In the main code I use a loop that counts its iterations in variable n. It's just a useless example for a task that takes some time and you have to replace it with your own code. However, the spinner is displayed as long as the loop runs. That means both the spinner and the loop run in parallel.
Steffen
Code: Select all
title MyFile.bat
set process=mmc.exe
set "ProcessName=disk management"
:LOOPMMC
TASKLIST | FINDSTR /i %process% >nul 2>&1 || goto Next
echo %ProcessName% is still running...
timeout /T 5 /Nobreak >nul 2>&1
goto LOOPMMC
:Next
What did you try and what didn't work?In the main code I use a loop that counts its iterations in variable n. It's just a useless example for a task that takes some time and you have to replace it with your own code.