使用超时命令或类似命令清除一行/移动光标 [英] Clear a line/move the cursor, using the Timeout command or similar

查看:87
本文介绍了使用超时命令或类似命令清除一行/移动光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来清除(CLS)单行(请参阅这个问题),但是发现解决方案涉及到移动光标,这需要额外的软件或对文件的修改,这并不理想.

I was trying to find a way to clear (CLS) a single line (see This Question), but found that the solutions, which involved moving the cursor, required extra software or modifications to files, which is not ideal.

但是,我后来发现TIMEOUT命令实际上移动了光标,可以通过以下代码进行演示:

However, I later noticed that the TIMEOUT command actually moves the cursor, which can be demonstrated with the following code:

@ECHO off
ECHO Notice how the cursor moves to the number.
ECHO Press [Ctrl]+[C] for an interesting result.
PAUSE
ECHO(
TIMEOUT 99999
PAUSE

如果在几秒钟后按Ctrl + C,则终止批处理作业"提示将覆盖数字后的TIMEOUT输出.任何键入也会继续覆盖它.

If Ctrl+C is pressed after a couple of seconds, the "Terminate Batch Job" prompt overwrites the TIMEOUT output after the number. Any typing also continues to overwrite it.

我正在寻找的是清除线条,更改线条或将光标移动到某处的任何方法,以及可能有用的任何类似方法. (我知道这有点含糊)

What I am looking for, is any way to clear a line, change the line, or move the cursor somewhere, and also anything similar that could be useful. (I know this is a bit vague)

一个想法是,如果可以用这样的方式修改标准输出,即光标仍在移动,则至少有可能在自定义行中的某一点获得一个变化的数字.

One idea was if it was possible to modify the stdout in such a way that the cursor still moved, it would at least be possible to get a changing number at one point in a custom line.

还可以异步执行TIMEOUT和ECHO命令,以产生与Ctrl + C类似的效果.

It might also be possible to asynchronously do both TIMEOUT and ECHO commands to have a similar effect to Ctrl+C.

将TIMEOUT标准输出重定向为nul不会提供LF字符.结合以下内容:

Redirecting the TIMEOUT stdout to nul gives no LF character. This in conjunction with:

<nul SET /P var=#
    REM echo without a LF character

...可能用于创建进度条.

...Could possibly be used to create progress bars.

欢迎任何具有类似效果的思想,想法或其他命令.

Any thoughts, ideas, or other commands with similar effects are welcome.

推荐答案

使用来自

Using answers from here you can have an increasing number printed.

重要的是,在下面的 insert_baskspace_here 处插入退格字符.

It is important to insert the backspace character in place of insert_baskspace_here below.

您将需要一个支持ASCII字符插入的编辑器.我使用了Ultraedit,但Notepad ++也可以.

You will need an editor that supports insertion of ASCII characters. I used Ultraedit but Notepad++ works too.

@echo off
setlocal enableextensions enabledelayedexpansion

set BS=insert_baskspace_here

Echo I printed 1 time
set /p "=I printed 2 times" <NUL

for /L %%I in (3,1,9) DO (
  timeout /t 1 > nul
  set /p "=!BS!!BS!!BS!!BS!!BS!!BS!!BS!%%I times" <NUL
)

输出开始于:

I printed 1 time
I printed 2 times

它每秒变化一次,并以以下内容结束:

It changes each second and finishes with:

I printed 1 time
I printed 9 times

进行一些更改,转盘还有一些进步:

A few changes and you have a little progress spinner wheel:

@echo off
setlocal enableextensions enabledelayedexpansion

set BS=

set /p "=Processing.../" <NUL

for /L %%J in (0,1,9) DO (
  for %%I in (-,\,^|,/,) DO (
    timeout /t 1 > nul
    set /p "=!BS!%%I" <NUL
  )
)

这篇关于使用超时命令或类似命令清除一行/移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆