标题: [特效代码] 求助 批处理字符显示显示在CMD窗口中间 [打印本页]
作者: enpany 时间: 2020-8-14 10:51 标题: 求助 批处理字符显示显示在CMD窗口中间
如何在不改变CMD窗口的尺寸下,让输出字符显示在窗口中间?
作者: zaqmlp 时间: 2020-8-14 12:48
用制表符或空格控制缩进
作者: a20150604 时间: 2020-8-14 12:51
WIN 10 有效- @echo off
- for /F %%a in ('echo prompt $E^| cmd') do set "_ESC=%%a"
-
- for /f "tokens=3,4 delims=, " %%A in (
- 'powershell -command "&{$H=get-host;$H.ui.rawui;}"^|findstr /b WindowSize'
- ) do set /a "_win_wid=%%A, _win_hei=%%B"
-
- set "str=hello world."
- set /a "y=_win_hei/2,x=_win_wid/2-6"
- set "_RGB_FACE=255;0;0"
- <nul set /p "=%_ESC%[38;2;%_RGB_FACE%m"
- <nul set /p "=%_ESC%[%y%;%x%H%str%
-
- set "str=VT100 on Windows 10"
- set /a "y=_win_hei/2+1,x=_win_wid/2-9"
- set "_RGB_FACE=0;255;0"
- <nul set /p "=%_ESC%[38;2;%_RGB_FACE%m"
- <nul set /p "=%_ESC%[%y%;%x%H%str%
- pause>nul
复制代码
作者: enpany 时间: 2020-8-14 14:03
回复 3# a20150604
WIN7下有没有效呢?
作者: a20150604 时间: 2020-8-14 18:05
回复 4# enpany
仅 Win 10 有效
来个简单特效- @echo off & setlocal enabledelayedexpansion
- REM VT100 参考
- REM https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
-
- for /F %%a in ('echo prompt $E^| cmd') do set "_ESC=%%a"
-
- REM 窗口尺寸也可以不指定
- mode 100,40
-
- REM 移动周期: 正整数, 越小, 移动越快
- set /a "cycle=2000"
-
- set "rgb_red=%_ESC%[38;2;255;0;0m"
- set "rgb_grn=%_ESC%[38;2;0;255;0m"
- set "rgb_blu=%_ESC%[38;2;0;0;255m"
- REM set "str=bbs.bathome.net"
- set "str=%rgb_red%bbs.%rgb_grn%bathome%rgb_blu%.net"
- set "str_clear=%rgb_red%bbs.%rgb_grn% %rgb_blu%.net"
-
- for /f "tokens=3,4 delims=, " %%A in (
- 'powershell -command "&{$H=get-host;$H.ui.rawui;}"^|findstr /b WindowSize'
- ) do set /a "_win_wid=%%A, _win_hei=%%B, x_ubound=_win_wid-14" & REM 14 为 str 的长度 - 1
-
- set /a "y= !random! %% _win_hei + 1, x= !random! %% x_ubound + 1"
- set /a "dx=dy=1"
-
- REM 隐藏光标 Hide the cursor
- <nul set /p "=%_ESC%[?25l"
-
- for /l %%a in (-9999999 1 9999999) do (
- set /a "m=%%a %% cycle"
- if !m!==0 (
- <nul set /p "=%_ESC%[!y!;!x!H%str_clear%"
-
- if !y! geq !_win_hei! set /a "dy=-1"
- if !y! leq 1 set /a "dy=1"
- if !x! geq !x_ubound! set /a "dx=-1"
- if !x! leq 1 set /a "dx=1"
- set /a "y+=dy,x+=dx"
- <nul set /p "=%_ESC%[!y!;!x!H%str%"
- )
- )
复制代码
作者: enpany 时间: 2020-8-14 18:40
回复 5# a20150604
膜拜大佬
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |