Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

[Add-On Macro for menus] - auto-window-size-detecting screen-wide line echoer

this is just an Add-On macro for batch-files that have menus or splash-screens or other significant visual display like that, it checks the window-width of the CommandPrompt window the batch-file is running in then generates and displays an exactly screen-wide line (line is by default made out of underscores you can change that to any character you want and keep changing it threw out the whole time your batch-file is running).


--
maybe im just comming up with a stupid idea cuz im on like no sleep, drunk, and on a bunch of xanax but i think this snipit of code for ppl to paste into their batch-files could rlly help ppl who are still kinda new to batch but getting better to have better looking menus and splash-screens and stuff and for ppl who know what theyre doing but just dont wanna do all that typing themselves, its two lines of code once you've paisted that macro in,
1) calling a section of the macro once in the begging of your script
2)everytime u want a screen-wide line in your CommandPrompt window to box-in menu options or something and u want those screen-wide lines to be always exactly screen-wide no matter if someone changed the size of the window since the batch-file was open or whatever all you have to do is type "%LineAcrossScreen%" then when that line of code "%LineAcrossScreen%" is being executed it checks how wide the CommandPrompt window is then generates a line thats exactly that width and echos it
--



this definitely isnt my best but whatever it popped into my mind even if its the first thing that i post on here thats not high-level & useful its just a display gimmick idc it might help someone out



how to use:
-put it anywhere in your Batch-File where it'll get skipped over
-to for lack of a better word to "activate" the maco type "call :SetUpLineBuilder" somewhere in your script before you need to use those screen-wide lines
-after you've "activated" the macro everytime you need a screen-wide line just type "%LineAcrossScreen%" as if its a regular command, just put it on its own line. and it'll check how wide the commandPrompt window is at the time it is being executed then generates and display/echos a screen-wide line (this takes a fraction of a second it u wont even notice)
-to change the character the line is made out of (again this is only after you've executed "call :SetUpLineBuilder") type: "%UseChar%{Character-you-wanna-use-go-here}" like if you wanted the line to be made of asterisks ("*") this time type "%UseChar%*" or if u want equal-signs ("=") "%UseChar%=" or if u want hash-tags ("#") "%UseChar%#" you get the pic (this just changes what the lines will be made of, it wont show the line when its executed, you'll have to execute another "%LineAcrossScreen%" after you change which character it is to do that)



Code
rem ******************************************************************************************************************************************
:BuildLine
if "%LineChar%"=="" set "LineChar=_"
for /f "tokens=2 skip=4" %%A in ('mode con: /status') do set "WindowColumns=%%A" & goto :GotColumnCount
:GotColumnCount
set "CharLine="
setlocal EnableDelayedExpansion
for /L %%A in (1,1,%WindowColumns%) do set "CharLine=!CharLine!!LineChar:~0,1!"
setlocal DisableDelayedExpansion
endlocal
echo %CharLine%
:SetUpLineBuilder
set "BuildLine=call :BuildLine"
set "UseChar=set LineChar="
set "LineAcrossScreen=call :BuildLine"
set "line=call :BuildLine"
goto :eof
rem ******************************************************************************************************************************************

[img]http://nhserver.x10host.com/hackforums/Add-On_macro/4.jpg[/img]
also when u do "call :SetUpLineBuilder" in your batch-file you're just adding 4 commands to your batch-file that are in the form of variables (its just easier for someone who didnt write this to remember the words of the variables' names than the text they represent) 3 of these executable variables all have the same value "call :BuildLine" you can just pick the one thats easiest for you to remember tbh idk why i made 3 commands for that maybe being way to barred out, drunk, and on like 3hours of sleep for the last few days had something do do with it idk, anyway these commands in the form of executable variables are "%LineAcrossScreen%" & "%BuildLine%" & "%line%". those are the ones you execute when u want to echo that screen-wide line

the last command is "%UseChar%", its the one that picks which character the screen-wide line is made of (default is underscore) u use it by putting the character you want to have the screen-wide lines made out of right next to it like this "%UseChar%_" ; "%UseChar%*" ; "%UseChar%=" ; "%UseChar%-" "%UseChar%#"


heres a quick script using this AddOn macro so you can see how the commands are executed and still understand just incase i did a shitty job explaining, its the same script as in the picture
Code
@goto :batch

--
This is just an example code for my screen-wide line generating Add-On macro;
the macro is at the bottom of this script, its marked in an obvious way.
--



:batch
@echo off
title example of a script using my Add-On Macro
rem **************************************************
rem this line of code activates the Add-On macro
call :SetUpLineBuilder
rem **************************************************
rem --
rem notice how I'm changing the width of CommandPrompt with the "mode con:" command to show
rem that this screen-wide line thing isnt just a variable full of characters of the default
rem CommandPrompt width, it actually reads the width before generating a screen-wide line
rem THE COMMAND-PROMPT WIDTH CHANGING COMMAND IS ON THE NEXT LINE:
mode con: cols=100 lines=20
rem --


:menu
cls
%LineAcrossScreen%
echo.1) option1 is make screen-wide lines equal-signs ["="]
echo.2) option2 is make screen-wide lines dashes ["-"]
echo.3) option3 is make screen-wide lines asterisks ["*"]
echo.4) option4 is make screen-wide lines under-scores ["_"]
%LineAcrossScreen%
choice /c 1234 >nul
if %errorlevel% EQU 1 %UseChar%=
if %errorlevel% EQU 2 %UseChar%-
if %errorlevel% EQU 3 %UseChar%*
if %errorlevel% EQU 4 %UseChar%_
goto :menu

rem the Add-On macro is in-between these lines and it also measures the width of CommandPromp's window everytime before it generates a line
rem ******************************************************************************************************************************************
:BuildLine
if "%LineChar%"=="" set "LineChar=_"
for /f "tokens=2 skip=4" %%A in ('mode con: /status') do set "WindowColumns=%%A" & goto :GotColumnCount
:GotColumnCount
set "CharLine="
setlocal EnableDelayedExpansion
for /L %%A in (1,1,%WindowColumns%) do set "CharLine=!CharLine!!LineChar:~0,1!"
setlocal DisableDelayedExpansion
endlocal
echo %CharLine%
:SetUpLineBuilder
set "BuildLine=call :BuildLine"
set "UseChar=set LineChar="
set "LineAcrossScreen=call :BuildLine"
set "line=call :BuildLine"
goto :eof
rem ******************************************************************************************************************************************
Oh neat, ill see if i could edit this a bit, good idea and thinking outside the box
"You can pick your friends, you can pick your nose, but you can't pick your friend's nose, because they usually get mad, butt we all know there hiding secrets in there" -James Bond
Here is as faster example!

Code
@echo off & setlocal EnableDelayedExpansion

title example of a script using my Add-On Macro

mode con: cols=100 lines=20


:menu
cls
call :BuildLine
echo.1) option1 is make screen-wide lines equal-signs ["="]
echo.2) option2 is make screen-wide lines dashes ["-"]
echo.3) option3 is make screen-wide lines asterisks ["*"]
echo.4) option4 is make screen-wide lines under-scores ["_"]
call :BuildLine
choice /c 1234 >nul
if %errorlevel% EQU 1 set LineChar==
if %errorlevel% EQU 2 set LineChar=-
if %errorlevel% EQU 3 set LineChar=*
if %errorlevel% EQU 4 set LineChar=_
goto :menu

:BuildLine
    if "!LineChar!"=="" set "LineChar=_"
    set "CharLine="
    if not defined WindowColumns (
        for /f "tokens=* delims=: " %%a in ('mode con: ^| find "Columns"') do set "WindowColumns=%%a"
        set "WindowColumns=!WindowColumns:~10!"
    )
    for /L %%A in (1,1,!WindowColumns!) do set "CharLine=!CharLine!!LineChar:~0,1!"
    echo !CharLine!
goto :eof


Possibly Related Threads...
Thread / Author Replies Views Last Post
by daarioJun 9, 2024 04:14 PM 10 301 Jun 9, 2024 04:14 PM
Last Post: Tyr
[C#] by Formula 1Dec 6, 2019 01:11 AM 23 708 Dec 6, 2019 01:11 AM
Last Post: itcorp
[C] by dogfoodsandwitchJul 13, 2019 11:17 PM 1 181 Jul 13, 2019 11:17 PM
Last Post: RedFishTeam8