How do I reorder the interface by the number of numbers / letters?

I am making a batch file (Microsoft.bat) and would like to know how can I automatically change the echo UI when moving out of X characters?

How to do it:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 50ms  |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 1ms  |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 200ms  |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

      

as I wish:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 50ms  |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 1ms   |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 200ms |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

      

Note 1: The number / letter can be arbitrarily varied from one digit to 3 digits.

Note 2: Symbols are next to represent what they will look like at the end that I am using here terminal font symbols that they did not convey that desire.

My code:

@Echo Off
Title Ping
Color 1f
mode con:lines=12 cols=39
setlocal enableextensions disabledelayedexpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Set "IPServidor=104.16.22.33"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set "lowPing=9999"
set "highPing=0"


Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


:doPing

set "ping="

for /f "tokens=9" %%a in ('
ping -n 2 "%IPServidor%" ^|find "ms,"
') do for /f "delims=m " %%b in ("%%a") do set "ping=%%~b"

Cls

if not defined ping  (
Echo.
Echo.
Echo.
Echo.
Echo  ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
echo  Β³ Β― O servidor nΓ†o est  respodendo! Β³
Echo  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo.
Echo.
Echo.
goto :doPing
)

Cls

if %ping% gtr %highPing% set "highPing=%ping%"
if %ping% lss %lowPing%  set "lowPing=%ping%"

Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping atual:  %ping%ms   Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping mΒ‘nimo: %lowPing%ms   Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping m ximo: %highPing%ms   Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

Goto :doPing

      

+3


source to share


2 answers


You can align your ping number correctly and use a fixed amount of spaces.

Try this right before displaying the variable %ping%

.

SET ping=  %ping%
SET ping=%ping:~-3%

      

Basically, the first line adds two spaces before the number, and then the second line takes the 3 rightmost characters.

So, if the value %ping%

is equal 1

, you get this:



β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping:   1ms |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

      

If the value %ping%

is equal 99

, you get the following:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping:  99ms |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

      

And, if the value %ping%

is equal 999

, you get this:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Ping: 999ms |
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

      

+4


source


Thanks to the help of the people here, I was able to complete my code and for that I am posting it below:



@Echo Off
Title Ping
Color 1f
mode con:lines=12 cols=39
setlocal enableextensions disabledelayedexpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Set "IPServidor=104.16.22.33"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set "lowPing=9999"
set "highPing=  0"


Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Calculando...       Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


:doPing

set "ping="

for /f "tokens=9" %%a in ('
ping -n 2 "%IPServidor%" ^|find "ms,"
') do for /f "delims=m " %%b in ("%%a") do set "ping=%%~b"

Cls

if not defined ping  (
Echo.
Echo.
Echo.
Echo.
Echo  ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
echo  Β³ Β― O servidor nΓ†o est  respodendo! Β³
Echo  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo.
Echo.
Echo.
goto :doPing
)

Cls

SET ping=   %ping%
SET ping=%ping:~-3%
if %ping% gtr %highPing% set "highPing=%ping%"
if %ping% lss %lowPing%  set "lowPing=%ping%"

Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping atual:  %ping%ms  Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping mΒ‘nimo: %lowPing%ms  Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Echo.
Echo        ΓšΓ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„Γ„ΒΏ
Echo        Β³ Β― Ping m ximo: %highPing%ms  Β³
Echo        ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

Goto :doPing

      

0


source







All Articles