Page 1 of 1

Spinner help

Posted: 19 Apr 2017 12:29
by batnoob
What is wrong with my code?
I want it to make a spinner, it is supposed to type a character backspace it, then type the next character, and so on. what it does instead is echo "- \ | /" over and over again

Code: Select all

@echo off
setlocal EnableDelayedExpansion

::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=$BS"    &set "$Details=Create $ESC Ascii-0x1B-27, Expansion insensitive"
::
::(
   for /f "delims=#" %%a in (

      '"prompt #$H# &echo on &for %%b in (1) do rem"'

   ) do (
      set "%$Defines%=%%a"
      set "%$Defines%=!$BS:~0,1!"
   )
set "s1=-"
set "s2=\"
set "s3=^|"
set "s4=/"
:spinner
echo %s1% %$BS% %s2% %$BS% %s3% %$BS% %s4% %$BS%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
FOR %%a IN (1,5,10) DO (call :spinner)

Re: Spinner help

Posted: 19 Apr 2017 12:42
by Aacini
batnoob wrote:What is wrong with my code?

Code: Select all

. . .

That you have not included a single explanation of what it supposeddly should do and, in case you have any problem with it, a clear description of what is the problem perhaps?

I suggest you to carefully read this post that, BTW, is placed at the very beginning of this forum!

Antonio

Re: Spinner help

Posted: 19 Apr 2017 13:35
by aGerman
ECHO won't work here because it always writes a new line.

Code: Select all

@echo off
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"

for /l %%i in () do for %%j in (^| / - \) do (
 <nul set /p "=%BS%%%j"
 >nul ping -n 1 localhost
)


Steffen

Re: Spinner help

Posted: 19 Apr 2017 13:38
by batnoob
Thank you, it works perfect!

Re: Spinner help

Posted: 19 Apr 2017 13:46
by batnoob
how to place that at the end of a line?
(e.g.

Code: Select all

set var=call:spinner
:spinner   -- Spins
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"

for /l %%i in () do for %%j in (^| / - \) do (
 <nul set /p "=%BS%%%j"
 >nul ping -n 1 localhost
)
GOTO:EOF

echo. %var%
)

Re: Spinner help

Posted: 19 Apr 2017 14:10
by aGerman
As I told you - ECHO won't work.

Code: Select all

@echo off
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"

<nul set /p "=Loading  "

for /l %%i in (1 1 50) do for %%j in (^| / - \) do (
 <nul set /p "=%BS%%%j"
 >nul ping -n 1 localhost
)
echo(

pause


Steffen

Re: Spinner help

Posted: 19 Apr 2017 14:20
by batnoob
Sorry, I don't know how to print any thing to the screen other than with echo (I'm a noob)

Re: Spinner help

Posted: 19 Apr 2017 14:23
by aGerman
With the SET /P trick, as you can see :wink: