today I'm here to give you all a new challenge!
今天,我要给你们所有人一个新的挑战!
Just joking: my problem is the caret of the Command Prompt. [The "entire" story is in the bottom"]
只是开玩笑:我的问题是命令提示符中的插入符号。[“整个”故事在底部“]
Short story long, I have to move the caret positions to ECHO
a new line in the same position.
That's because I have to print only few strings [about three lines]; making a CLS
every time it blinks because of the speed of the execution.
简而言之,我必须移动插入符号的位置,以便在相同的位置回显新行。这是因为我只需要打印很少的字符串[大约三行];由于执行速度的原因,每次CLS都会闪烁。
I tried some things, also using the <NUL SET /P "=InsertHereString"
, but there's always the problem of what I already ECHO
ed that doesn't disappear!
我尝试了一些方法,也使用了
So here's my request: There's a method to move that blinking bunch of pixel allowing to write a string starting from a certain point of the CMD?
所以我的要求是:有一种方法可以移动闪烁的像素,允许从CMD的某个点开始写字符串吗?
BOTTOM:
The "entire" story is that I made a sort of installer in batch, copying and linking some applications from a removable drive.
Now, I also made a status bar saying in percentage what is done.
Under the status bar I want to show what actually the program is doing, but when there are [for example] a lot of file in a directory to link or copy, it makes a list instead of erasing the previous thing, so at the moment I'm simply ECHO
ing a " - Done!"
or a" - Failed!"
string next to the main string.
I asked for that because in another language [C++] I found a method that I used to make a PacMan simulation.
It consists in a method that want an X
and an Y
variable that identify the caret position in a Cartesian plane where the (0,0)
position is the up-left corner of the Command Prompt.
总结:“整个”故事是我批量制作了一种安装程序,从可移动驱动器复制和链接一些应用程序。现在,我还制作了一个状态栏,以百分比表示已完成的内容。在状态栏下面,我想要显示程序实际在做什么,但是当一个目录中有很多文件要链接或复制时,它会列出一个列表,而不是删除前面的内容,所以现在我只是简单地回应一个“-Done!”或者“-失败!”主字符串旁边的字符串。我这么做是因为在另一种语言[C++]中,我找到了一种方法,我可以用它来模拟吃豆人。它包含一个方法,该方法需要一个X和一个Y变量来标识插入符号在笛卡尔平面中的位置,其中(0,0)位置是命令提示的左上角。
Thanks for your time!
耽误您时间,实在对不起!
更多回答
I already tried with the CursorPos
method, but the exe doesn't work in windows 8!
我已经尝试了CursorPos方法,但可执行文件在Windows8中不起作用!
Breaking news: I also tried the CursorPos
method in windows seven, but occurs the same issue and it doesn't work. The ASCII
method results obsolete for windows eight [I have to try in seven...]. Any other idea?
突发新闻:我也在Windows7中尝试了CursorPos方法,但出现了同样的问题,而且不起作用。对于Windows 8,ASCII方法的结果是过时的[我必须在7分钟内尝试...]。还有别的主意吗?
BG v2.5 (unicode)
BG v2.5(Unicode)
http://batch.xoo.it/t2238-BG-exe-Utility-for-Batch-Games.htm
Http://batch.xoo.it/t2238-BG-exe-Utility-for-Batch-Games.htm
BG.EXE is a tool for print text color in cmd.exe. It accepts regular
expressions for print ascii characters. It also have useful functions.
Locate row column
::locate the position of cursor in row and column specified, zero index based.
Call it: bg Locate 0 0
and the cursor jumps there.
叫它:bg找到0,光标就会跳到那里。
Or
或
CursorPos.exe
CursorPos.exe
http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
Http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
Get or set cursor position.
CursorPos [[±]col [±]row]
If no parameter is given, return current cursor position as
col+(row<<16) in ERRORLEVEL.
If any coordinate have sign, the position given is relative to the
current one.
If cursor is moved, the Ascii code of the character at new position is
returned in ERRORLEVEL.
It takes a little bit to get used to using cursorpos. Here's a proof of concept. Not sure whether this is similar to what you had in mind, but I think the trickery you have in mind is possible. Anything is possible given enough beer.
习惯使用游标需要一点时间。这是一个概念的证明。我不确定这是否与你所想的相似,但我认为你所想的诡计是可能的。只要有足够的啤酒,一切皆有可能。
Save this as pacman.bat
and run it. The result is spectacular :P (Moreso if your console is using a truetype font.)
将其另存为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
ANSICON provides ANSI escape sequences for Windows console programs. It provides much the same functionality as ANSI.SYS
does for MS-DOS.
ANSICON为Windows控制台程序提供ANSI转义序列。它提供的功能与ANSI.sys为MS-DOS提供的功能大致相同。
https://github.com/adoxa/ansicon
Https://github.com/adoxa/ansicon
You can just compile this microprogram of my design:
你可以只编译我设计的这个微程序:
// CONSOLE
#include <stdp>
i32 wmain()
{
p|DC|SCP(0,0)|TB|P;
return 0;
}
Yes, this is all it takes to reset console cursor position to origin. It also disables cursor and trims buffer to the size of actual text, and then pauses and waits for input, but if you need just cursor position than p|SCP(x,y);
is enough.
是的,这就是将控制台光标位置重置为原点所需的全部操作。它还禁用光标并将缓冲区修剪到实际文本的大小,然后暂停并等待输入,但如果只需要光标位置,则p|scp(x,y);就足够了。
To learn more about how <stdp>
does all this magic you can find the source for it here.
要了解有关
如何实现所有这些魔术的更多信息,您可以在这里找到它的源代码。
更多回答
That's it, that's it! I already tried CursorPos, but for a reason or another, it doesn't even start in my pc... BG resolved my problem, thanks a lot guy!
就是这样,就是这样!我已经试过CursorPos了,但由于某种原因,它甚至无法在我的电脑上启动……BG解决了我的问题,非常感谢小伙子!
Hey there, thanks for the spot, this batch create CursorPos and it works... I don't know why, but the CursorPos.exe.hex found in link doesn't make a good exe for my pc... Maybe I'm doing something wrong...
嘿,谢谢你的现场,这批创建的CursorPos和它的工作…我不知道为什么,但在LINK中找到的CursorPos.exe.hex不适合我的电脑。也许我做错了什么..。
It's my 11 secret herbs and spices. That, or my heredoc magic. :)
这是我的11种秘方香草和香料。或者是我的异教徒魔法。:)
What is even this madness? I don't get what is the point of all this nonsense if you can just compile a tiny C/C++ program with SetConsoleCursorPosition(0,0)
.
这到底是什么疯狂的事情?如果你能用SetConsoleCursorPosition(0,0)编译一个很小的C/C++程序,我就不明白这些废话有什么用。
Madness? This! Is! Sparta! Also, the question was tagged with the [batch] tag so I provided a batch solution. Nice job unearthing a 10-year-old post though.
疯狂?这!是!斯巴达!另外,这个问题使用了[Batch]标签,所以我提供了一个批次解决方案。不过,挖掘出一个10年前的帖子干得不错。
ANSICON
have problem with the nvidia's x64 drivers and I work most of the time in computers with nvidia x64 boards. I'm sorry for making the problem harder, but my wish is to make the batch file executable in every [Windows] SO, starting from XP x86, to Eight x64!
ANSICON对NVIDIA的x64驱动程序有问题,我大部分时间都在安装NVIDIA x64主板的电脑上工作。很抱歉让问题变得更难,但我的愿望是使批处理文件在每个[Windows]中都可执行,因此,从XP x86开始,到8个x64!
我是一名优秀的程序员,十分优秀!