vi中是否有交互式选项,我可以在其中创建展开菜单?

时间:2018-08-25 05:10:27

标签: linux shell vi

我希望为我的程序创建一个文件,用户可以打开该文件并选择其选项,然后在VI或其他编辑器中运行计算。有点像VI中的菜单,您可以在其中突出显示一个单词并展开/更改该主题。然后,只有我要突出显示一个选项并查看所有可能的选择,并允许他们选择一个。有没有办法创建这样的文件/功能?

1 个答案:

答案 0 :(得分:0)

不确定您的意思是什么,但是您可以像这样用Python创建一个简单的GUI,让您的用户从列表中选择参数,然后为FORTRAN程序编写“设置” 文件并启动它当按下按钮时:

#!/usr/local/bin/python3
from guizero import App, ListBox, Text, PushButton

def StartThatPuppy():
   print("Starting FORTRAN...")
   # Write currently selected settings to config file
   # subprocess.call('/Users/fred/program.exe')

app = App(title="FORTRAN Parameter Setup", width=300, height=200)

t=Text(app, text="Select optimisation method")
listbox = ListBox(app,
                  items=["Method A", "Method B", "Method C (beta)", "Naive Method"],
                  selected="Method B",
                  scrollbar=True)
listbox.height=3
listbox.width=20

t=Text(app, text="Select threshold")
listbox = ListBox(app,
                  items=["1%", "2%", "5%", "10%"],
                  selected="5%",
                  scrollbar=True)
listbox.height=3
listbox.width=20

button = PushButton(app, text="Start FORTRAN", command=StartThatPuppy)
app.display()

看起来像这样:

enter image description here

更多示例和文档为here


或者,如果您想要文本的内容而又不需要GUI,则可以像在RaspberryPi上使用whiptail一样使用raspi-config

enter image description here

另一个选项可能是dialog,文档here

可能看起来像这样:

dialog  --title "FORTRAN Parameter Setup" "$@" \
        --checklist "You can choose your threshold here.\n\
  Press SPACE to toggle an option on/off. \n\n\
  What threshold do you want?" 20 61 5 \
        "1%"  "Default threshold" ON \
        "2%"  "Less sensitive" off \
        "5%"  "Can be noisy" off \
        "Unlimited"    "Potentially too many results" off

retval=$?

enter image description here