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
source to share
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 |
ββββββββββββββ
source to share
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
source to share