gpt4 book ai didi

batch-file - 批处理文件中的反向换行

转载 作者:行者123 更新时间:2023-12-02 18:28:27 27 4
gpt4 key购买 nike

我正在寻找一种在批处理文件中使用反向换行的方法(如果我正确理解了这个概念)。预先列出它 - 它必须是批处理兼容的 - 不能使用外部可执行文件,因为它将运行的安全环境。

我有以下内容来设置换行/回车:


REM Produces a Carriage Return effect for use later.
for /f %%a in ('copy "%~f0" nul /z') do set "cr=%%a"
REM Produces a Linefeed effect for later use. WARNING - must keep 2 lines of code blank after this command!
set lf=^


现在,这可以按预期使用 set/p 提示等产生很酷的效果。我想要完成的是使用此方法的带有“文本框”的提示,但使用像下面这样:


set /p "var=*************************************************************************************!lf!!cr!* Enter the Street Address of this Store. [Use as many characters as you need] *!lf!!cr!* Address:_____________________________________________________________________ *!lf!!cr!*************************************************************************************!REVERSE_LF!!cr!* Address:"

REM Intended Output:

REM NOTE placed a | symbol to indicate where expected cursor would be when user is typing the Address

REM *************************************************************************************
REM * Enter the Street Address of this Store. [Use as many characters as you need] *
REM * Address:|____________________________________________________________________ *
REM *************************************************************************************

现在,我之前已经做了一些非常类似的事情来实现类似的目标,但没有成功地提供一个有边界的解决方案。

下面给出的示例与上面几乎相同,但没有边框:


set /p "var=Enter the Street Address of this Store. [Use as many characters as you need]!lf!!cr!Address:_____________________________________________________________________!cr!Address:"

Rem Output:

Rem Note: as before - using pipe symbol to indicate where cursor is when using this method

Rem Enter the Street Address of this Store. [Use as many characters as you need]
REM Address:|____________________________________________________________________

Windows 命令行/批处理文件语法有这样的东西吗?

最佳答案

就像 @Ken White 已经说过的那样,没有反向换行,但您可以使用 VT100(ANSI 转义码)来移动光标,至少在 windows10 上是这样。

@echo off

REM Produce an escape character
for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "ESC=%%a"

echo **********************
echo * Address: _________ *
echo **********************
set /p "=%ESC%[2A%ESC%[11C" < nul
set /p Address=

ESC[2A - 将光标向上移动两行
ESC[11C - 将光标向右移动 11 个位置

或者更好,不计数量

echo **********************
echo * Address: %ESC%7_________ *
echo **********************
set /p "=%ESC%8" < nul
set /p Address=

ESC7 - 保存当前光标位置
ESC8 - 恢复上次保存的光标位置

关于batch-file - 批处理文件中的反向换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69762848/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com