[Cmd] writing in the same line over & over ...

Discussion in 'Scripting' started by Dark Dinosaur, Dec 19, 2022.

  1. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,225
    120
    #1 Dark Dinosaur, Dec 19, 2022
    Last edited: Dec 19, 2022
    this is something seen first time in black bird script,
    after little investigating, it's 2 chars combined together

    ALT 0 1 3 + ALT 0 3 2
    (0D) Carriage Return + (20) Space


    here some working example,
    with color option and this,
    it's a good option to visual your script.
    (it work in console new too)

    Code:
    
    @cls
    @echo off
    cd /d "%~dp0"
    setlocal EnableExtensions EnableDelayedExpansion
    
    :: Run as Admin with native shell, any path, params, loop guard, minimal i/o, by AveYo
    >nul reg add hkcu\software\classes\.Admin\shell\runas\command /f /ve /d "cmd /x /d /r set \"f0=%%2\" &call \"%%2\" %%3" & set "_= %*"
    >nul fltmc || if "%f0%" neq "%~f0" ( cd.>"%tmp%\runas.Admin" & start "%~n0" /high "%tmp%\runas.Admin" "%~f0" "%_:"=""%" &exit /b )
    
    :: make sure before script is running as Admin
    :: explorer.exe exist in all version, so we can use it for our benefit
    for /f %%a in ('copy %SystemRoot%\explorer.exe nul /z') do set "RET=%%a"
    
    rem Based on BlackBird Idea
    rem don't know yet what is this !break! char ?
    rem also it work only in !! and not %%
    rem interesting behavior
    
    echo:
    echo Working ............
    echo Working ............
    echo Working ............
    echo Working ............
    echo:
    
    for /l %%i in (0,40,1000) do (
        call :drawProgressBar 000 Process %%i%%%%
        >nul 2>&1 ping 100.0.0.0 -w 1 -n 2
    )
    
    echo:
    echo:
    echo Done^^!
    echo:
    pause
    exit /b
    
    :drawProgressBar
    <nul set /p "=%*!RET!"
    endlocal
    goto :eof
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,225
    120
    and a bonus, we can use space in Choice Command.
    we need thus char's (we can use Notepad++ to generate them easily)
    put them like this "!RET! _SPACE_ _SPACE_ _SPACE_ What do you like to do today ?"

    Code:
        :: ALT 0 0 8
        set "BS="
      
        :: ALT 0 0 0 7
        set "BEL="
    
        (set RET=^
    %=Do not remove this line=%
    )
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. itsmemario1

    itsmemario1 MDL Expert

    Sep 10, 2012
    1,047
    280
    60
    *offtopic*
    I discovered Alt+987 as a kid by accident █...I was like, woah...then I started doing ascii/ansi art. ^^
     
  4. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,761
    5,225
    120
    #4 Dark Dinosaur, Dec 19, 2022
    Last edited: Dec 19, 2022
    (OP)
    Not seems to work
    This pipeline s**t .. :bye:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,447
    1,424
    60
    #5 rpo, Dec 29, 2022
    Last edited: Dec 30, 2022
    If you want to write in the same line over & over, you can use powershell :
    Code:
    @echo off
    for /l %%n in (1,1,20) do (
    powershell "write-host '.' -nonewline"
    timeout 1 >nul
    )
    echo;
    pause
    for overwriting, insert a carriage return and you can play with colors :
    Code:
    @echo off
    for /l %%n in (1,1,20) do (
    powershell "write-host \"`r*** test ***\" -nonewline -foregroundcolor red"
    timeout 1 >nul
    powershell "write-host \"`r*** test ***\" -nonewline -foregroundcolor blue"
    timeout 1 >nul
    )
    echo;
    pause