切断文本而不是换行 - 批处理

Cut off text instead of going into a new line - Batch

我正在尝试在批处理文件中显示 cmdtext.txt。我希望它在没有 space 剩余而不是进入新行时切断(如下所示),因为它破坏了“样式”和该文件的实际用途。 (批处理文件最大化运行,因此文本将有足够的 space 来显示)

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

Batch 没有用于此类任务的内置函数。当您希望格式化或限制输出时,您需要考虑需要采取哪些步骤来实现目标。

首先,考虑您需要哪些信息。在此任务中,您需要:

  • 控制台的列宽
    • 通过使用 for /f 循环遍历模式命令来获取它
  • 要格式化的数据

接下来,为了将输出限制为控制台宽度,可以使用 Substing 修改 trim 您正在格式化为控制台宽度的数据:


@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;_______________\/////////__\///______________\///__\////////////_________________________\///___________\/////________\/////_____\/////////__\//////////____________________________________________________________________________________________________________________