17个显示彩色字符和动画的批处理代码(二)

网友投稿 1339 2022-09-16

17个显示彩色字符和动画的批处理代码(二)

17个显示彩色字符和动画的批处理代码(二)

​​上接第一篇​​

代码6:现场编译出.exe工具软件

这是bat/-混合体。将代码保存为 .bat运行,可以现场编译出一个.exe可执行文件(编译和运行都需要 -框架),手动指定字符和参数输出。

co -s string [-f foreground] [-b background] [-n] [-e]

-s  要显示的字符串

-f 前景色 0~15

-b 背景色 0~15

-n 在末尾显示一个空行(默认不显示)

-e 处理转义符,包括  \n,  \r,  \t,  \f,  \v,  \b 比如\n是回车+换行,\r是换行,\t是制表符

字符串里若有空格,输入方法是:ALT+小键盘25

@if (@X)==(@Y) @end /* jscript comment@echo offsetlocalfor /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( set "jsc=%%v")if not exist "%~n0.exe" ( "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0")%~n0.exe %*endlocal & exit /b %errorlevel%*/import System;var arguments:String[] = Environment.GetCommandLineArgs();var newLine = false;var output = "";var foregroundColor = Console.ForegroundColor;var backgroundColor = Console.BackgroundColor;var evaluate = false;var currentBackground=Console.BackgroundColor;var currentForeground=Console.ForegroundColor;//jsEscapes = { 'n': '\n', 'r': '\r', 't': '\t', 'f': '\f', 'v': '\v', 'b': '\b'};function decodeJsEscape(_, hex0, hex1, octal, other) { var hex = hex0 || hex1; if (hex) { return String.fromCharCode(parseInt(hex, 16)); } if (octal) { return String.fromCharCode(parseInt(octal, 8)); } return jsEscapes[other] || other;}function decodeJsString(s) { return s.replace( // Matches an escape sequence with UTF-16 in group 1, single byte hex in group 2, // octal in group 3, and arbitrary other single-character escapes in group 4. /\\(?:u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(.))/g, decodeJsEscape);}function printHelp( ) { print( arguments[0] + " -s string [-f foreground] [-b background] [-n] [-e]" ); print( " " ); print( " string String to be printed" ); print( " foreground Foreground color - a " ); print( " number between 0 and 15." ); print( " background Background color - a " ); print( " number between 0 and 15." ); print( " -n Indicates if a new line should" ); print( " be written at the end of the "); print( " string(by default - no)." ); print( " -e Evaluates special character " ); print( " sequences like \\n\\b\\r and etc "); print( "" ); print( "Colors :" ); for ( var c = 0 ; c < 16 ; c++ ) { Console.BackgroundColor = c; Console.Write( " " ); Console.BackgroundColor=currentBackground; Console.Write( "-"+c ); Console.WriteLine( "" ); } Console.BackgroundColor=currentBackground; }function errorChecker( e:Error ) { if ( e.message == "Input string was not in a correct format." ) { print( "the color parameters should be numbers between 0 and 15" ); Environment.Exit( 1 ); } else if (e.message == "Index was outside the bounds of the array.") { print( "invalid arguments" ); Environment.Exit( 2 ); } else { print ( "Error Message: " + e.message ); print ( "Error Code: " + ( e.number & 0xFFFF ) ); print ( "Error Name: " + e.name ); Environment.Exit( 666 ); }}function numberChecker( i:Int32 ){ if( i > 15 || i < 0 ) { print("the color parameters should be numbers between 0 and 15"); Environment.Exit(1); }}if ( arguments.length == 1 || arguments[1].toLowerCase() == "-help" || arguments[1].toLowerCase() == "-help" ) { printHelp(); Environment.Exit(0);}for (var arg = 1; arg <= arguments.length-1; arg++ ) { if ( arguments[arg].toLowerCase() == "-n" ) { newLine=true; } if ( arguments[arg].toLowerCase() == "-e" ) { evaluate=true; } if ( arguments[arg].toLowerCase() == "-s" ) { output=arguments[arg+1]; } if ( arguments[arg].toLowerCase() == "-b" ) { try { backgroundColor=Int32.Parse( arguments[arg+1] ); } catch(e) { errorChecker(e); } } if ( arguments[arg].toLowerCase() == "-f" ) { try { foregroundColor=Int32.Parse(arguments[arg+1]); } catch(e) { errorChecker(e); } }}Console.BackgroundColor = backgroundColor ;Console.ForegroundColor = foregroundColor ;if ( evaluate ) { output=decodeJsString(output);}if ( newLine ) { Console.WriteLine(output); } else { Console.Write(output); }Console.BackgroundColor = currentBackground;Console.ForegroundColor = currentForeground;

代码7:用findstr命令实现文字着色

::这是曾经写的,又稍微改进了一下。@echo offset str=青天有月来几时 我今停杯一问之 人攀明月不可得 月行却与人相随setlocal enabledelayedexpansionset col=CAD9Bfor /f "tokens=1-4 delims= " %%1 in ("%str%") do (echo.for %%m in (%%1 %%2 %%3 %%4) do (set s=%%mfor /l %%a in (0,1,6) do (call set b=0%%col:~!x!,1%%set /a x+=1&if !x!==5 (set x=0)set c=!s:~%%a,1!set/p= !c! findstr /a:!b! .* "!c!*"del !c!ping /n 1 /w 500 127.1>nul&ping /n 1 /w 500 127.1>nul&ping /n 1 /w 500 127.1>nul)echo.&echo.))pause>nul&exit

代码8:用findstr命令实现文字着色

@echo offtitle a game for youtube::演示怎样从批处理打开网页explorer "EnableDelayedExpansionfor /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "DEL=%%a")echo say the name of the colors, don't readcall :ColorText 0a "blue"call :ColorText 0C "green"call :ColorText 0b "red"echo(call :ColorText 19 "yellow" call :ColorText 2F "black"call :ColorText 4e "white"goto :Beginoffile:ColorTextecho off "%~2"findstr /v /a:%1 /R "^$" "%~2" nuldel "%~2" > nul 2>&1goto :eof:Beginoffileecho.echo.pause

代码9:用findstr命令实现文字着色

@Echo OffCall :Color 9 "##################" \nCall :Color F ""Call :Color A "Final"Call :Color B " Version"Call :Color C " 20"Call :Color F "" \nCall :Color 9 "##################" \nPause >NulExit /B:Color:: v20 deprecated.:: Arguments: hexColor text [\n]:: Supported in windows XP, 7, 8.:: In XP extended ascii characters are printed as dots.:: For print quotes, use empty text.SetLocal EnableExtensions EnableDelayedExpansionSet "Text=%~2"If Not Defined Text (Set Text=^")Subst `: "!Temp!" >Nul &`: &Cd \If Not Exist `.7 (Echo(|(Pause >Nul &Findstr "^" >`)Set /P "=." >>` `.3Set /P "=%%#%%#%%#%%#%%#" `.5Set /P "=%%#%%#%%#%%#%%#%%#%%#" `.7))Set /P "LF=" <` &Set "LF=!LF:~0,1!"For %%# in ("!LF!") Do For %%_ In (\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"For /F delims^=^ eol^= %%# in ("!Text!") Do (If #==#! SetLocal DisableDelayedExpansionIf \==%%# (Findstr /A:%~1 . \` NulType `.3) Else If /==%%# (Findstr /A:%~1 . /.\` NulType `.5) Else (Echo %%#\..\`>`.datFindstr /F:`.dat /A:%~1 .Type `.7))If "\n"=="%~3" (Echo()Goto :Eof

代码10:用findstr命令实现文字着色

@echo offcall :color 04 " SOME TEXT TO DISPLAY HERE IN COLOR"echo.echo.echo.call :color 06 " SOME TEXT TO DISPLAY HERE IN COLOR"echo.echo.echo.call :color 02 " SOME TEXT TO DISPLAY HERE IN COLOR"echo.echo.pausegoto :EOF:Color:: v23c:: Arguments: hexColor text [\n] ...:: \n -> newline ... -> repeat:: Supported in windows XP, 7, 8.:: This version works using Cmd /U:: In XP extended ascii characters are printed as dots.:: For print quotes, use empty text.SetLocal EnableExtensions EnableDelayedExpansionSubst `: "!Temp!" >Nul &`: &Cd \SetLocal DisableDelayedExpansionEcho(|(Pause >Nul &Findstr "^" >`)Cmd /A /D /C Set /P "=." >>` `.1Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >NulCopy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >NulCopy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul):__ColorSet "Text=%~2"If Not Defined Text (Set Text=^")SetLocal EnableDelayedExpansionFor %%_ In ("&" "|" ">" "<") Do Set "Text=!Text:%%~_=^%%~_!"Set /P "LF=" <` &Set "LF=!LF:~0,1!"For %%# in ("!LF!") Do For %%_ In (\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"For /F delims^=^ eol^= %%# in ("!Text!") Do (If #==#! EndLocalIf \==%%# (Findstr /A:%~1 . \` NulType `.3) Else If /==%%# (Findstr /A:%~1 . /.\` NulType `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.datFindstr /F:`.dat /A:%~1 .Type `.7))If "\n"=="%~3" (ShiftEcho()ShiftShiftIf ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :EofGoto :__Color

代码11:使用color命令实现文字着色

循环往复亮瞎眼

echo off:: color /? 可以查询颜色表:zecho 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符echo 显示彩色字符color 01color 02color 03color 04color 05color 06color 07color 08color 09color 0Acolor 0Bcolor 0cgoto z

​​跳转至第三篇​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:C# 数据操作系列 - 15 SqlSugar 增删改查详解(cctv5)
下一篇:2021年全球十大数据安全事件
相关文章

 发表评论

暂时没有评论,来抢沙发吧~