简单的菜单系统perl

发布于 2025-02-12 07:32:28 字数 407 浏览 0 评论 0原文

我正在尝试在一个简单的菜单上运行10-20个命令(CentOS),而不是从头开始写作,而是考虑使用Ncurses或类似于此图像的内容,非常基本

“

那将运行任何命令,也许在完成后结束时暂停,这就是这样。 我寻找了一段时间来寻找一个基本的示例菜单,可以抓取和不运气。 发现了大量的参考文献,有90%的简单链接,过时的等。 如果有人使用诅咒的示例,或者是一种更好的简单方法,让我只能从菜单中运行一堆控制台命令,那就太好了。

谢谢!

I'm trying to have 10-20 commands I run (centos) on a simple menu, Instead of writing from scratch, I was thinking of using ncurses or something similar to this image, very basic

Sample

Then that would run whatever command, maybe pause at the end when completed and thats it.
I looked for a while for a basic example menu to grab and go and no luck.
Found a ton of references with 90% simply dead links, outdated etc.
If someone has either an example using curses or a better simple way for me to just have a bunch of console commands run from the menu, that would be great.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痞味浪人 2025-02-19 07:32:28

这是一个示例,使用 cursess :: ui 和a curses :: ui :: listbox 显示菜单:

use strict;
use warnings;
use Curses::UI;

my $cui = Curses::UI->new( -color_support => 1 );
my $win1 = $cui->add('win1', 'Window');

my $listbox = $win1->add(
    'lb',
    'Listbox',
    -vscrollbar => 'left',
    -title      => "Select Playlist",
    -border     => 1,
    -wraparound => 1,
    -values     => [ "Radio",
                 "Recently added",
                 "SD-Alternative",
                 "SD-Country",
                 "SD-Pop",
                 "SD-Rock",
                 "TV Shows",
                 "Voice Memos",
                 "iTunes U",
             ],
    -onchange   => \&selected_item,
);
$cui->draw;
$cui->set_binding( \&exit_dialog , "\cQ");
$cui->mainloop();

sub selected_item {
    my $item = $listbox->get_active_value();
    my $return = $cui->dialog(
        -message   => "You selected item: $item. Do you want to quit?",
        -title     => "Item selected",
        -buttons   => ['yes', 'no'],
    );
    exit 0 if $return;
}

sub exit_dialog {
    my $return = $cui->dialog(
        -message   => "Do you really want to quit?",
        -title     => "Are you sure?",
        -buttons   => ['yes', 'no'],
    );
    exit 0 if $return;
}

Here is an example using Curses::UI and a Curses::UI::Listbox to display the menu:

use strict;
use warnings;
use Curses::UI;

my $cui = Curses::UI->new( -color_support => 1 );
my $win1 = $cui->add('win1', 'Window');

my $listbox = $win1->add(
    'lb',
    'Listbox',
    -vscrollbar => 'left',
    -title      => "Select Playlist",
    -border     => 1,
    -wraparound => 1,
    -values     => [ "Radio",
                 "Recently added",
                 "SD-Alternative",
                 "SD-Country",
                 "SD-Pop",
                 "SD-Rock",
                 "TV Shows",
                 "Voice Memos",
                 "iTunes U",
             ],
    -onchange   => \&selected_item,
);
$cui->draw;
$cui->set_binding( \&exit_dialog , "\cQ");
$cui->mainloop();

sub selected_item {
    my $item = $listbox->get_active_value();
    my $return = $cui->dialog(
        -message   => "You selected item: $item. Do you want to quit?",
        -title     => "Item selected",
        -buttons   => ['yes', 'no'],
    );
    exit 0 if $return;
}

sub exit_dialog {
    my $return = $cui->dialog(
        -message   => "Do you really want to quit?",
        -title     => "Are you sure?",
        -buttons   => ['yes', 'no'],
    );
    exit 0 if $return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文