批处理之家's Archiver

netbenton 发表于 2021-11-7 21:37

Win10纯cmd实现字符模式真彩显示(VT100)

从523066680的发现取光标位置开始才知道ansi,发现win10控制台对ansi的支持挺强大的,不知道是从什么时候起可以自定义显示真彩的。
有其它版操作系统的可尝试一下。

[url]http://bbs.bathome.net/thread-58523-1-1.html[/url][code]@echo off
set '=!%让叹号的变量最后才解开%
::测试环境:windows 10

setlocal enabledelayedexpansion
title CMD 控制台ansi控制显示,实现字符模式真彩显示

::文本只能保存为ansi编码,其它编码可能出错。

rem 取控制符到变量。(1BH=27=033)
for /F "tokens=1 delims=#" %%a in ('"prompt #$E# & echo on & for %%b in (1) do rem"') do set "ESC=%%a"

set "BC=!esc![38;2;!'!nn!'!;112;123m!'!say!'!!esc![0m"
rem 做一个属性在!nn!,要显示的字符在!say!的模块。

for /l %%a in (0,1,255) do (set nn=%%a&set "say=        %%a"&set "say=!say:~-4!"&set "ecbu=!ecbu!%bc%")

rem 把要显示的所有字符串放到临时变量(缓存)
set /p "in=%ecbu%"<nul
set/p =回车退出
[/code]

Batcher 发表于 2021-11-8 11:49

[u]两篇文章供大家查阅[/u]

VT100 参考
[url=https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences]https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences[/url]

使用 Win10 命令提示符自带命令实现彩色输出
[url=https://c1ino.github.io/c1ino/2019/08-03-colored-echo-in-win10-command-prompt]https://c1ino.github.io/c1ino/2019/08-03-colored-echo-in-win10-command-prompt[/url]

[u]几个小例子供大家参考[/u]

简单的 VT100 绘图引擎,支持 24 位色!
[url]http://bbs.bathome.net/thread-63749-1-1.html[/url]

批处理彩色指针时钟示例
[url]http://bbs.bathome.net/thread-54470-1-1.html#pid225601[/url]

批处理特效:一串字符到处撞拖影
[url]http://bbs.bathome.net/thread-59450-1-1.html#pid242599[/url]

批处理代码显示图片
[url]http://bbs.bathome.net/thread-59440-1-1.html[/url]

批处理字符显示在CMD窗口中间
[url]http://bbs.bathome.net/thread-56525-1-1.html#pid231619[/url]

批处理把命令结果的某一部分显示为不同的颜色
[url]http://bbs.bathome.net/thread-59826-1-1.html[/url]

批处理年会抽奖
[url]https://mp.weixin.qq.com/s/FSIqqusbwS9i9MAIhXIwzA[/url]

批处理逐字显示彩色字符串
[url]http://bbs.bathome.net/thread-61903-1-1.html#pid252648[/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.