Page 1 of 1

Animated loading screen

Posted: 16 Jun 2019 17:37
by infectedw
Any script witch contains loading animated script? I working on my program in batch and need some sort of loading screen...

Thanks!

Re: Animated loading screen

Posted: 17 Jun 2019 13:37
by IcarusLives
Generally whatever it is that is loading, you can prompt it within the code to do so.

For example...

Code: Select all

@echo off

for /l %%a in (1,1,100) do (
	cls
	echo Currently working: %%a...
)
echo done
pause
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.

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

Posted: 20 Jun 2019 12:59
by aGerman
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.

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
)
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

Re: Animated loading screen

Posted: 21 Jul 2019 05:18
by infectedw
Thanks aGerman this will work awesome!

Re: Animated loading screen

Posted: 26 Jul 2019 14:08
by bt.player
You can using this.

Code: Select all

@echo off

for /l %%a in (1,1,100) do echo|set /p="#"
echo.done.
pause>nul

Re: Animated loading screen

Posted: 27 Jul 2019 15:53
by Eureka!
bt.player wrote:
26 Jul 2019 14:08
You can using this.
[...]
Thank you !!
Very elegant (and looking deceivingly simple ...)

Re: Animated loading screen

Posted: 02 Aug 2019 14:47
by bakemonogatari
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
that's pretty cool.

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
I would like the spinner to run in MyFile.bat as long as mmc.exe is running, how to adapt that?

Re: Animated loading screen

Posted: 04 Aug 2019 02:23
by aGerman
I hoped I was clear enough:
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.
What did you try and what didn't work?

Steffen

Re: Animated loading screen

Posted: 04 Aug 2019 11:02
by bakemonogatari
it was an infinite loop ... but I could do what I wanted with another loading code so it's ok