Animated loading screen
Moderator: DosItHelp
Animated loading screen
Any script witch contains loading animated script? I working on my program in batch and need some sort of loading screen...
Thanks!
Thanks!
-
- Posts: 175
- Joined: 17 Jan 2016 23:55
Re: Animated loading screen
Generally whatever it is that is loading, you can prompt it within the code to do so.
For example...
This "loading" would be quite fast though. If you're looking for something "PURELY" aesthetic, then that is different. A real loading bar is a visual representation of things being added to your pc or variables being saved, etc.
If you're looking for something that is purely for looks, then you can use the code above, with a slight modification.
For example...
Code: Select all
@echo off
for /l %%a in (1,1,100) do (
cls
echo Currently working: %%a...
)
echo done
pause
If you're looking for something that is purely for looks, then you can use the code above, with a slight modification.
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
Re: Animated loading screen
Most of those "loading screens" are just a waste of time because
- either there is nothing to load
- or they are synchronously executed
If you have some code that really takes time and you want to let the user know, then you have to animate it asynchronously while your actual task is executed.
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
- either there is nothing to load
- or they are synchronously executed
If you have some code that really takes time and you want to let the user know, then you have to animate it asynchronously while your actual task is executed.
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
)
Steffen
Re: Animated loading screen
Thanks aGerman this will work awesome!
Re: Animated loading screen
You can using this.
Code: Select all
@echo off
for /l %%a in (1,1,100) do echo|set /p="#"
echo.done.
pause>nul
Last edited by aGerman on 27 Jul 2019 14:31, edited 1 time in total.
Reason: code tags
Reason: code tags
-
- Posts: 21
- Joined: 08 Jul 2019 05:22
Re: Animated loading screen
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
MyFile.bat launches diskmgmt.msc, then MyFile.bat waits as long as diskmgmt.msc stays running
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
Re: Animated loading screen
I hoped I was clear enough:
Steffen
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.
Steffen
-
- Posts: 21
- Joined: 08 Jul 2019 05:22
Re: Animated loading screen
it was an infinite loop ... but I could do what I wanted with another loading code so it's ok