Ad

Cut Off Text Instead Of Going Into A New Line - Batch

- 1 answer

I am trying to display cmdtext.txt in a batch file. I want it to just cut off (just as shown below) when there is no space left instead of going into a new line, because it ruins the "style" and the actual purpose of this file. (The batch file runs maximized, so the text would have enough space to display)

________/\\\\\\\\\__/\\\\____________/\\\\__/\\\\\\\\\\\\___________________/\\\\\\\\\\\\\\\______________________________/\\\\\\___________________________________________________________________________________________________________________________________________
______/\\\////////__\/\\\\\\________/\\\\\\_\/\\\////////\\\________________\///////\\\/////______________________________\////\\\__________________________________________________________________________________________________________________________________________
_____/\\\/___________\/\\\//\\\____/\\\//\\\_\/\\\______\//\\\_____________________\/\\\______________________________________\/\\\_________________________________________________________________________________________________________________________________________
_____/\\\_____________\/\\\\///\\\/\\\/_\/\\\_\/\\\_______\/\\\__/\\\\\\\\\\\_______\/\\\___________/\\\\\________/\\\\\_______\/\\\_____/\\\\\\\\\\________________________________________________________________________________________________________________________
_____\/\\\_____________\/\\\__\///\\\/___\/\\\_\/\\\_______\/\\\_\///////////________\/\\\_________/\\\///\\\____/\\\///\\\_____\/\\\____\/\\\//////________________________________________________________________________________________________________________________
______\//\\\____________\/\\\____\///_____\/\\\_\/\\\_______\/\\\_____________________\/\\\________/\\\__\//\\\__/\\\__\//\\\____\/\\\____\/\\\\\\\\\\______________________________________________________________________________________________________________________
________\///\\\__________\/\\\_____________\/\\\_\/\\\_______/\\\______________________\/\\\_______\//\\\__/\\\__\//\\\__/\\\_____\/\\\____\////////\\\_____________________________________________________________________________________________________________________
___________\////\\\\\\\\\_\/\\\_____________\/\\\_\/\\\\\\\\\\\\/_______________________\/\\\________\///\\\\\/____\///\\\\\/____/\\\\\\\\\__/\\\\\\\\\\____________________________________________________________________________________________________________________
_______________\/////////__\///______________\///__\////////////_________________________\///___________\/////________\/////_____\/////////__\//////////____________________________________________________________________________________________________________________
Ad

Answer

Batch has no builtins for tasks like this. When you wish to format or restrict output, you need to consider what steps you need to take to achieve the goal.

First, consider what information you need. In this task, you need:

  • The width of the console in columns
    • Acquire this by iterating over the mode command with a for /f loop
  • The data to format

Next, For the purpose of restricting output to the consoles width, Substing modification can be used to trim the data you are formatting to the consoles width:


@Echo off
Call:Header
Set /A Y=lines,X=columns
Timeout /t 2 /NoBreak
mode 90,30
Call:Header
Timeout /t 2 /NoBreak
mode %X%,%Y%
Goto:Eof


:Header
(Set LF=^


%= Empty lines above required =%)
 Setlocal EnableDelayedExpansion
 For /f "tokens=1,2 Delims=: " %%G in ('mode ^| findstr /li "col lin"')Do Set "$%%G=%%H"
 Set "Output="
 For /f "usebackq tokens=1 delims=:1;" %%G in (`type "%~f0" ^| %SystemRoot%\System32\findstr.exe /blc:":1;" "%~f0"`) Do (
  Set "Line=%%G"
  Set "Output=!Output!!Line:~0,%$Columns%!!LF!"
 )
 Echo(!Output!
 For /f "tokens=1,2 Delims=;" %%G in ("lines=!$lines!;Columns=!$Columns!")Do Endlocal & (
  Set "%%G"
  Set "%%H"
 )
Exit /b


 

:1;________/\\\\\\\\\__/\\\\____________/\\\\__/\\\\\\\\\\\\___________________/\\\\\\\\\\\\\\\______________________________/\\\\\\___________________________________________________________________________________________________________________________________________
:1;______/\\\////////__\/\\\\\\________/\\\\\\_\/\\\////////\\\________________\///////\\\/////______________________________\////\\\__________________________________________________________________________________________________________________________________________
:1;_____/\\\/___________\/\\\//\\\____/\\\//\\\_\/\\\______\//\\\_____________________\/\\\______________________________________\/\\\_________________________________________________________________________________________________________________________________________
:1;_____/\\\_____________\/\\\\///\\\/\\\/_\/\\\_\/\\\_______\/\\\__/\\\\\\\\\\\_______\/\\\___________/\\\\\________/\\\\\_______\/\\\_____/\\\\\\\\\\________________________________________________________________________________________________________________________
:1;_____\/\\\_____________\/\\\__\///\\\/___\/\\\_\/\\\_______\/\\\_\///////////________\/\\\_________/\\\///\\\____/\\\///\\\_____\/\\\____\/\\\//////________________________________________________________________________________________________________________________
:1;______\//\\\____________\/\\\____\///_____\/\\\_\/\\\_______\/\\\_____________________\/\\\________/\\\__\//\\\__/\\\__\//\\\____\/\\\____\/\\\\\\\\\\______________________________________________________________________________________________________________________
:1;________\///\\\__________\/\\\_____________\/\\\_\/\\\_______/\\\______________________\/\\\_______\//\\\__/\\\__\//\\\__/\\\_____\/\\\____\////////\\\_____________________________________________________________________________________________________________________
:1;___________\////\\\\\\\\\_\/\\\_____________\/\\\_\/\\\\\\\\\\\\/_______________________\/\\\________\///\\\\\/____\///\\\\\/____/\\\\\\\\\__/\\\\\\\\\\____________________________________________________________________________________________________________________
:1;_______________\/////////__\///______________\///__\////////////_________________________\///___________\/////________\/////_____\/////////__\//////////____________________________________________________________________________________________________________________
Ad
source: stackoverflow.com
Ad