3

今天我来给大家一个新的挑战!

开个玩笑:我的问题是命令提示符的插入符号。[“整个”故事在底部”]

长话短说,我必须将插入符号位置移动到ECHO同一位置的新行。那是因为我只需要打印几个字符串 [大约三行];CLS由于执行速度的原因,每次闪烁时都会制作 a 。

我尝试了一些东西,也使用了<NUL SET /P "=InsertHereString",但总是存在我已经ECHO编辑的问题并没有消失!

所以这是我的要求:有一种方法可以移动闪烁的一堆像素,允许从 CMD 的某个点开始写入字符串?

底部:“整个”故事是我批量制作了一种安装程序,从可移动驱动器复制和链接一些应用程序。现在,我还制作了一个状态栏,以百分比表示已完成的工作。在状态栏下我想显示程序实际上在做什么,但是当一个目录中有很多文件要链接或复制时,它会列出一个列表而不是删除以前的东西,所以此刻我只是在主字符串旁边添加ECHO一个" - Done!"或一个字符串。" - Failed!"我要求这样做是因为在另一种语言 [C++] 中,我找到了一种用于制作 PacMan 模拟的方法。它包含一个需要一个方法X和一个Y变量,该变量标识笛卡尔平面中的插入符号位置,该(0,0)位置是命令提示符的左上角。

谢谢你的时间!

4

3 回答 3

3

BG v2.5 (unicode)

http://batch.xoo.it/t2238-BG-exe-Utility-for-Batch-Games.htm

BG.EXE 是一个在cmd.exe 中打印文字颜色的工具。它接受打印 ascii 字符的正则表达式。它还具有有用的功能。

定位行列::定位光标在指定行和列中的位置,基于零索引。

调用它:bg Locate 0 0光标跳到那里。


或者

光标位置.exe

http://www.dostips.com/forum/viewtopic.php?f=3&t=3428

获取或设置光标位置。

CursorPos [[±]col [±]row]

如果没有给出参数,则在 ERRORLEVEL 中以 col+(row<<16) 的形式返回当前光标位置。

如果任何坐标有符号,则给出的位置是相对于当前坐标的。

如果光标移动,则在 ERRORLEVEL 中返回新位置字符的 Ascii 代码。

于 2013-03-04T17:47:04.273 回答
3

习惯使用 cursorpos 需要一点时间。这是一个概念证明。不确定这是否与您的想法相似,但我认为您想到的诡计是可能的。只要有足够的啤酒,一切皆有可能。

将此另存为pacman.bat并运行它。结果非常壮观:P(如果您的控制台使用的是 truetype 字体,则更是如此。)

@echo off
setlocal enabledelayedexpansion

Rem cursorpos and colorshow created by Antonio Perez Ayala
Rem http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
call :heredoc cursorpos >cursorpos.hex && goto endCursorpos
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B0[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]55B5B8FD11D4D6AE11D4D6AE11D4D6AE9FCBC5AE18D4D6AEED
F4C4AE13D4D6AE5269636811D4D6AE[8]5045[2]4C010200EB84E24F[8]E0000F010B01050C0002[3]02[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]30[3]02[6]03[5]10[2]10[4]10[2]10[6]10[11]1C20[2]28[84]20[2]1C[27]2E74657874[3]4201[3]10[3]02[3]02[14]20[2]60
2E7264617461[2]F6[4]20[3]02[3]04[14]40[2]40[8]E806[3]50E81301[2]558BEC83C4E06AF5E81201[2]8945FC8D45E650FF75FCE8
FD[3]668B45EC668945E4E8BC[3]E8DB[3]803E0075058B45EAEB5C803E3D750646E8C6[3]668B4DEAE84A[3]8945EAE8B5[3]803E
007418803E2C750646E8A5[3]668B4DE4E829[3]668945EC8B5DEA53FF75FCE8AE[3]8D45E650536A018D45E350FF75FCE895[3]0F
B645E3C9C333C032DB33D28A164680FA2B740880FA2D750980CB0280CB018A164680FA30720F80FA39770A80EA306BC00A03
C2EBE9F6C301740BF6C302740366F7D86603C14EC3CCCCCCCCCCCCCCCCCCCCCCCCCCE847[3]8BF08A06463C2275098A06463C
2275F9EB0C8A06463C20740484C075F54EC38A06463C2074F94EC3CCFF2514204000FF2500204000FF2504204000FF250820
4000FF250C204000FF25102040[191]6E20[2]8C20[2]9C20[2]BA20[2]D620[2]6020[6]4420[10]E820[3]20[22]6E20[2]8C20[2]9C20[2]BA
20[2]D620[2]6020[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265656E427566666572496E666F
[2]6A0147657453746448616E646C65[2]380252656164436F6E736F6C654F757470757443686172616374657241006D025365
74436F6E736F6C65437572736F72506F736974696F6E[2]E600476574436F6D6D616E644C696E6541006B65726E656C33322E
646C6C[268]
:endCursorpos

call :heredoc colorshow >colorshow.hex && goto endShow
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B8[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]5549FA721128942111289421112894219F3787211A289421ED
088621132894215269636811289421[16]5045[2]4C0103001DDBEB50[8]E0000F010B01050C0006[3]04[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10[4]10[2]10[6]10[11]2420[2]28[84]20[2]24[27]2E74657874[3]DE04[3]10[3]06[3]04[14]20[2]60
2E7264617461[2]3201[3]20[3]02[3]0A[14]40[2]402E64617461[3]20[4]30[3]02[3]0C[14]40[2]C0[472]E806[3]50E8A304[2]558BEC81C4
E8DFFFFFFC6AF5E8A404[2]8945FC6800304000FF75FCE88804[2]8B1D043040008D85E8DFFFFF50536A018D45FA50FF75FCE8
7E04[2]668B45FA66A316304000D41086C4D510668945F88DBDF8DFFFFF89BDF4DFFFFFE81304[2]E83204[2]8A064684C00F84
4803[2]3C2F0F858C[3]2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE85F03[2]8BBDF4DFFFFF8A064684
C00F840F03[2]3C20750C668B45FA66A316304000EBA73C2F750C668B45F866A316304000EB972C303C0976082C073C0F7602
2C208A264684E40F84D602[2]80FC20741286C42C303C0976082C073C0F76022C20D51066A316304000E95CFFFFFF3C227520
8A064684C00F84A502[2]3C227405880747EBEC8A06463C2274F4E938FFFFFF3C300F82C6[3]3C390F87BE[3]E8A102[2]3C2A74
083C5874043C7875278ADC468A06463C300F826102[2]3C390F875902[2]E87A02[2]0FB6CC8AC3F3AAE9F0FEFFFF80FC207379
80FC09751F8B0D0430400003CF2B8DF4DFFFFF83E10783E908F7D9B020F3AAE9C7FEFFFF2BBDF4DFFFFF741A506A008D85E8
DFFFFF5057FFB5F4DFFFFFFF75FCE83D02[2]588BBDF4DFFFFF88276A008D85E8DFFFFF506A01FFB5F4DFFFFFFF75FCE8E302
[2]6800304000FF75FCE8BE02[2]E972FEFFFF882747E96AFEFFFF2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFF
FF75FCE8E101[2]8BFE4F33DB889DF2DFFFFF8A063C3A74118885F3DFFFFF3C20746084C0745C46EBE9889DF2DFFFFFC6060046
8A06463C2D7509C685F2DFFFFF02EB0B3C2B750AC685F2DFFFFF018A06463C300F827001[2]3C390F876801[2]E86901[2]8885
F3DFFFFF3C20740884C00F855101[2]84E40F841001[2]8ADCC60600680020[2]8D85F8DFFFFF5057E80702[2]85C00F84F1[3]85
DB0F84CF[3]3BC30F84C7[3]7C2D80BDF2DFFFFF00741DF685F2DFFFFF01750A2BC30185F4DFFFFFEB0A2BC3D1E80185F4DFFF
FF8BC3E998[3]2BD88BBDF4DFFFFF03F889BDECDFFFFF50B0208BCBF3AA80BDF2DFFFFF007443F685F2DFFFFF02741C6A018D
85E8DFFFFF5053FFB5ECDFFFFFFF75FCE8C9[3]33DBEB1E8BFBD1EF2BDF6A018D85E8DFFFFF5057FFB5ECDFFFFFFF75FCE8A7
[3]588BF86A018D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE88C[3]6A028D85E8DFFFFF5053FFB5ECDFFFFFFF75FCE874[3]EB1A
8BF86A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE858[3]8A85F3DFFFFF88068DBDF8DFFFFF89BDF4DFFFFFE9A8FCFFFF2B
BDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE81F[3]0FB745FAC9C3240F8AE08A06463C30720C3C397708
2C30D50A8AE0EBED4EC3558BEC6A00FF7514FF7510FF750CFF7508E8B2[3]8B4D1066837D180172137708010D18304000EB46
030D18304000894D10578B7D0C66A116304000F366AB8B0D04304000FF751451FF7510FF750CFF7508E876[3]5F6800304000FF
7508E84A[3]C705183040[5]C9C21400CCCCCCCCCCCCCCCCE853[3]8BF08A06463C2275098A06463C2275F9EB0C8A06463C2074
0484C075F54EC38A06463C2074F94EC3CCFF2500204000FF2504204000FF2508204000FF250C204000FF2510204000FF2514
204000FF2518204000FF251C2040[291]7020[2]7E20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]4C20[10]2421[3]20[22]7020[2]7E
20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265
656E427566666572496E666F[2]1301476574456E7669726F6E6D656E745661726961626C6541006A0147657453746448616E
646C65[2]370252656164436F6E736F6C654F7574707574417474726962757465[2]EE025772697465436F6E736F6C654100F2
025772697465436F6E736F6C654F757470757441747472696275746500E600476574436F6D6D616E644C696E6541006B6572
6E656C33322E646C6C[720]
:endShow

call :heredoc hexchar >hexchar.vbs && goto endHexchar
Rem Hex digits to Ascii Characters conversion
Rem Antonio Perez Ayala - Apr/14/2012

Dim line,index,count
line = WScript.StdIn.ReadLine()
While line <> ""
   index = 1
   While index < len(line)
      If Mid(line,index,1) = "[" Then
         index = index+1
         count = 0
         While Mid(line,index+count,1) <> "]"
            count = count+1
         WEnd
         For i=1 To Int(Mid(line,index,count))
            WScript.StdOut.Write Chr(0)
         Next
         index = index+count+1
      Else
         WScript.StdOut.Write Chr(CByte("&H"&Mid(line,index,2)))
         index = index+2
      End If
   WEnd
   line = WScript.StdIn.ReadLine()
WEnd
:endHexchar

:: Create cursorpos.exe and colorshow.exe
for %%I in (cursorpos colorshow) do (
    cscript /nologo /B /E:VBS HexChar.vbs < "%%I.hex" > "%%I.exe"
    del %%I.hex
)
del hexchar.vbs

:: ---------------------------------------------------
:: Supporting applications all created.  Now use them.
:: ---------------------------------------------------

call :DefineColorCodes

set /P I="Waiting... "<NUL
cursorpos
call :GetCoords Cols Lines

for /l %%A in (1, 1, 3) do (

    colorshow /%Black% "  " /%Yellow%%Black% "(<" /%White% " o  o  o  o  o"

    for /l %%I in (2, 1, 15) do (
        call :sleep 100
        set /a pos=%Cols% + %%I
        cursorpos !pos! %Lines%
        set /a e=%%I %% 2
        if #!e!==#1 (
            colorshow /%Black% " " /%Yellow%%Black% "(<"
        ) else colorshow /%Black% " " /%Yellow%%Black% "(-"
    )

    for /l %%I in (15, -1, 2) do (
        call :sleep 100
        set /a pos=%Cols% + %%I
        cursorpos !pos! %Lines%
        set /a e=%%I %% 2
        if #!e!==#1 (
            colorshow /%Yellow%%Black% ">)" /%Black% " "
        ) else colorshow /%Yellow%%Black% "-)" /%Black% " "
    )
    cursorpos=%Cols%,%Lines%

)

:: ---------------------------------------------------
:: End of main script
:: ---------------------------------------------------
echo Done.
del cursorpos.exe colorshow.exe sleep.vbs
goto :EOF

:: ---------------------------------------------------
:: Subroutines
:: ---------------------------------------------------

:GetCoords Cols= Lines=
set /A "%1=%errorlevel%&0xFFFF, %2=(%errorlevel%>>16)&0xFFFF"
exit /B

:DefineColorCodes
set HexDigit=0123456789ABCDEF
set c=-1
for %%c in ( Black Blue  Green  Aqua  Red  Purple  Brown  White
             Grey  LBlue LGreen LAqua LRed LPurple Yellow BWhite ) do (
   set /A c+=1
   for %%C in (!c!) do set %%c=!HexDigit:~%%C,1!
)
exit /B

:sleep <ms>
if not exist sleep.vbs (echo Wscript.Sleep^(Wscript.Arguments^(0^)^)>sleep.vbs)
cscript /nologo sleep.vbs %1
goto :EOF

:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
    set "line=%%A" && set "line=!line:*:=!"
    if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
    if "!line:~0,13!"=="call :heredoc" (
        for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
            if #%%i==#%1 (
                for /f "tokens=2 delims=&" %%I in ("!line!") do (
                    for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
                )
            )
        )
    )
)
goto :EOF
于 2013-03-04T20:52:26.057 回答
0

ANSICON 为 Windows 控制台程序提供 ANSI 转义序列。ANSI.SYS它提供与MS-DOS相同的功能。

https://github.com/adoxa/ansicon

于 2013-03-04T13:13:30.667 回答