作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将简单的批处理菜单文件升级为混合批处理/ powershell混合。我遇到了这个问题-batch menu outlines and design-它具有一个不错的Powershell界面。但是,我不知道如何正确设置菜单选项!你能说明我吗?
代码如下:
<# : Batch portion # Original Code by rojo@StackOverflow
REM https://stackoverflow.com/users/1683264/rojo)
@echo off & setlocal enabledelayedexpansion
set "menu[0]=Open GenNBO Helper"
set "menu[1]=Open Jmol@NBO Viewer Helper"
set "menu[2]=Open Jmol *"
set "menu[3]=Start NBO"
set "menu[4]=Start Multiwfn"
set "menu[5]=EXIT"
set "default=5"
powershell -noprofile "iex (gc \"%~f0\" | out-string)"
echo Option Selected: !menu[%ERRORLEVEL%]!.
goto :EOF
:GENNBO
CLS
ECHO Starting GenNbo Helper v1.33
cd L:\GennboHelper\
start GennboHelper_1.33.jar
GOTO MENU
#JMOLNBO
:JMOLNBO
CLS
ECHO Starting JmolNbo Viewer Helper v2.1
cd L:\JmolNboVHelper2.1\
start JmolNbo21W.jar
GOTO MENU
#JMOL
:JMOL
CLS
ECHO Starting Jmol v14.30.1
cd L:\Jmol-14.30.1-binary\jmol-14.30.1
start Jmol.jar
GOTO MENU
#NBO
:NBO
CLS
ECHO Starting NBO 6.0 Environment CMD
cd L:\nbo6\
start C:\Windows\System32\cmd.exe /c L:\Portland\PGI\win64\19.10\pgi_dos.bat
GOTO MENU
#MWFN
:MWFN
CLS
ECHO Starting Multiwfn
L:\Multiwfn
start L:\Multiwfn\Multiwfn.exe
GOTO MENU
: end batch / begin PowerShell hybrid chimera #>
$menutitle = "=== MENU ==="
$menuprompt = "Use the arrow keys. Hit Enter to select."
$maxlen = $menuprompt.length + 6
$menu = gci env: | ?{ $_.Name -match "^menu\[\d+\]$" } | %{
$_.Value.trim()
$len = $_.Value.trim().Length + 6
if ($len -gt $maxlen) { $maxlen = $len }
}
[int]$selection = $env:default
$h = $Host.UI.RawUI.WindowSize.Height
$w = $Host.UI.RawUI.WindowSize.Width
$xpos = [math]::floor(($w - ($maxlen + 5)) / 2)
$ypos = [math]::floor(($h - ($menu.Length + 4)) / 3)
$offY = [console]::WindowTop;
$rect = New-Object Management.Automation.Host.Rectangle `
0,$offY,($w - 1),($offY+$ypos+$menu.length+4)
$buffer = $Host.UI.RawUI.GetBufferContents($rect)
function destroy {
$coords = New-Object Management.Automation.Host.Coordinates 0,$offY
$Host.UI.RawUI.SetBufferContents($coords,$buffer)
}
function getKey {
while (-not ((37..40 + 13 + 48..(47 + $menu.length)) -contains $x)) {
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode
}
$x
}
# goo.gl/IAmdR6
function WriteTo-Pos ([string]$str, [int]$x = 0, [int]$y = 0,
[string]$bgc = [console]::BackgroundColor, [string]$fgc = [Console]::ForegroundColor) {
if($x -ge 0 -and $y -ge 0 -and $x -le [Console]::WindowWidth -and
$y -le [Console]::WindowHeight) {
$saveY = [console]::CursorTop
$offY = [console]::WindowTop
[console]::setcursorposition($x,$offY+$y)
Write-Host $str -b $bgc -f $fgc -nonewline
[console]::setcursorposition(0,$saveY)
}
}
function center([string]$what) {
$what = " $what "
$lpad = " " * [math]::max([math]::floor(($maxlen - $what.length) / 2), 0)
$rpad = " " * [math]::max(($maxlen - $what.length - $lpad.length), 0)
WriteTo-Pos "$lpad $what $rpad" $xpos $line blue yellow
}
function menu {
$line = $ypos
center $menutitle
$line++
center " "
$line++
for ($i=0; $item = $menu[$i]; $i++) {
# write-host $xpad -nonewline
$rtpad = " " * ($maxlen - $item.length)
if ($i -eq $selection) {
WriteTo-Pos " > $item <$rtpad" $xpos ($line++) yellow blue
} else {
WriteTo-Pos " $i`: $item $rtpad" $xpos ($line++) blue yellow
}
}
center " "
$line++
center $menuprompt
1
}
while (menu) {
[int]$key = getKey
switch ($key) {
37 {} # left or up
38 { if ($selection) { $selection-- }; break }
39 {} # right or down
40 { if ($selection -lt ($menu.length - 1)) { $selection++ }; break }
# number or enter
default { if ($key -gt 13) {$selection = $key - 48}; destroy; exit($selection) }
}
}
最佳答案
在powershell ...
行之后,您只需回显选定的菜单点。您需要将其转换为goto
等if "!menu[%errorlevel%]!"=="Open GenNBO Helper" goto :GENNBO
等(每个菜单项一行)。
我建议改为更改标签,并仅使用一个goto
:
powershell ...
echo Option Selected: !menu[%ERRORLEVEL%]!.
goto :menu%errorlevel%
goto :eof
:menu0
REM formerly :GENNBO
CLS
...
goto :menu
:menu1
REM formerly :JMOLNBO
...
etc.
关于powershell - 选项去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59862699/
我通常将JS和CSS Assetic Assets 放置在DefaultBundle中,但我认为放置它们的最佳位置是在app / Resources / public /(js | css)文件夹中。
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是一名优秀的程序员,十分优秀!