2

I am trying to wrap my head around Curses/NCurses (still don't understand the difference) and perl, more exactly the Curses::UI modules, more exactly the Curses::UI::Widget package - see http://search.cpan.org/~mdxi/Curses-UI/lib/Curses/UI/Widget.pm .

For understanding it, I would like to see some super-simple "Hello World" Curses::UI::Widget to start there.

There is a simple example in Curses::UI::Widget documentation, but that doesn't work, since it calls $this->generic_focus and it's undefined, and I have no idea what it should actually do.

Is there some actual tutorial for writing Curses::UI widgets, or at least some working examples?

edit: To make myself clear: the basic text-editor from the documentation works from me, but now I would like to write my own widgets and I am not sure which functions to implement and how.

Mainly, I am not sure what should method focus do and if I have to implement the method generic_focus or not.

edit 2:

For example, in the linked documentation above, the function generic_focus is written as if it was implemented in Curses::UI::Widget, but it actually isn't implemented anywhere. What is going on exactly?

Karel Bílek
  • 36,467
  • 31
  • 94
  • 149

2 Answers2

5

Example borrowed from this tutorial

enter image description here

#!/usr/bin/perl -w

use strict;
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1 );
my @menu = (
    { -label => 'File',
        -submenu => [
            { -label => 'Exit      ^Q', -value => \&exit_dialog  }
        ]
    },
);
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;
}
my $menu = $cui->add(
    'menu','Menubar',
    -menu => \@menu,
    -fg  => "blue",
);
my $win1 = $cui->add(
    'win1', 'Window',
    -border => 1,
    -y    => 1,
    -bfg  => 'red',
);
my $texteditor = $win1->add("text", "TextEditor",
    -text => "Here is some text\n"
    . "And some more");
$cui->set_binding(sub {$menu->focus()}, "\cX");
$cui->set_binding( \&exit_dialog , "\cQ");
$texteditor->focus();
$cui->mainloop();

The difference between curses and ncurses is that ncurses is an open source clone of curses. See https://stackoverflow.com/a/1517768/465183

Community
  • 1
  • 1
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
2

The simple examples from the documentation page work for me:

use Curses::UI;
my $cui = Curses::UI->new( -clear_on_exit => 1);
$cui->dialog("Hello, world!");
choroba
  • 231,213
  • 25
  • 204
  • 289