批处理文件 VT100 实现 [英] Batch File VT100 implementation

查看:24
本文介绍了批处理文件 VT100 实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当涉及到用于在屏幕上显示文本文件的批处理程序时,我试图阻止屏幕闪烁.它必须更新,我想出的唯一方法是循环程序并清除屏幕.

I am trying to stop screen flicker when it comes to my batch program that is used to display a text file on the screen. It has to update and the only way I have come up with is to loop the program and clear the screen.

这是我当前的代码.

::Begin the refresh loop
::---------------------------------------------------------------
:Refresh


type "%ud%\ChatTerminal\Msg.txt

Sleep 1

cls


Goto Refresh
:Break Refresh
::---------------------------------------------------------------
::Refresh Loop Ends
::---------------------------------------------------------------

经过一番研究,我来到了这篇文章:如何从批处理文件动画中删除闪烁?

After some research I came to this post: How do I remove flickering from a batch file animation?

问题是我不知道从哪里开始实施.

The issue is that I would not know where to start with the implementation.

推荐答案

T3RR0R 的解决方案覆盖现有行而不删除旧行的其余部分.因此,当新行较短时,旧行的其余部分会继续显示.

T3RR0R's solution overwrites existing lines without deleting the rest of the old line. So when the new line is shorter, the rest of the old line keeps showing.

这可以通过逐行写入文件,删除该行的其余部分来解决.可悲的是,这会减慢速度并因此重新引入闪烁(至少对于超过一行的文件).

That could be solved by writing the file line by line, deleting the rest of the line. Sadly that slows things down and thus re-introduces the flicker (at least for files with more than one line).

作为替代方案,仅写入已更改的文件.它仍然闪烁,但现在就在文件更新时.显示文件后,取消设置 archive 属性.每当 Windows 写入文件时,它都会再次设置属性,我们用它来确定文件是否已更改.

As an alternative, only write the file, if it has changed. It still flickers, but now just when the file is updated. After displaying the file, unset the archive attribute. Whenever Windows writes to the file, it sets the attribute again, which we use to determine if the file has changed.

@echo off
set "file=%ud%\ChatTerminal\Msg.txt"
:loop
attrib "%file%"|findstr /b "A" >nul && (
  cls
  type "%file%"
  attrib "%file%" -a
)
timeout 1 >nul
goto :loop

奖励:这不使用转义码,因此它可以在每个 Windows 版本上运行(可能有一些已弃用的 Windows 版本默认没有 timeout,但可以替换它需要时使用 ping)

Bonus: this doesn't use Escape codes, so it runs on every Windows version (possibly there are a few deprecated Windows versions that didn't have timeout by default, but it can be replaced with ping when needed)

这篇关于批处理文件 VT100 实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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