多选菜单- @echo off & cd /d "%~dp0"
- setlocal enabledelayedexpansion
- call :get_menu "menu-item-1" "menu-item-2" "menu-item-3" "menu-item-4" "menu-item-5"
- echo 选择了%_ret%项
- pause&exit
-
- REM 多选择菜单
- REM [返回值 _ret]
- REM [参数 菜单列表 ...]
- :get_menu
- set "_n=0"
- for %%i in (%*) do set /a "_n+=1"
- if "%_cur%"=="" set "_cur=1"
- call :show_menu %_cur% %*
- echo.
- choice /C "WSAY" /N /M "WS切换,A标记,Y确定 "
- if "%errorlevel%"=="4" ( set "_ret=" & (for /f "tokens=2 delims==_" %%i in ('set _n_ 2^>nul') do set "_ret=!_ret! %%i") & goto :eof)
- if "%errorlevel%"=="3" if "!_n_%_cur%!"=="1" ( set "_n_%_cur%=" ) else ( set "_n_%_cur%=1" )
- if "%errorlevel%"=="2" if %_cur% lss %_n% set /a "_cur+=1"
- if "%errorlevel%"=="1" if %_cur% gtr 1 set /a "_cur-=1"
- cls&goto :get_menu %*
- REM 显示菜单
- REM [参数 选择项 菜单列表 ...]
- :show_menu
- set /a "_i=%~1,_j=1" & shift /1
- :L1
- if "%~1"=="" goto :eof
- if "%_i%"=="%_j%" ( call :show_str 255 0 0 %~1 & goto :L2)
- if "!_n_%_j%!"=="1" ( call :show_str 0 255 0 %~1 & goto :L2)
- call :show_str 255 255 255 %~1
- :L2
- shift /1 & set /a "_j+=1" & goto :L1
- REM 显示彩色字符串
- REM [参数 R,G,B,str]
- :show_str
- echo.[38;2;%~1;%~2;%~3m%~4[m
- goto :eof
复制代码
|