Thanks for the answer, it looked very promising, but unfortunately that doesn't change anything... do_one_event() still waits for a keypress, although the timeout was set to 0 and 1, for testing.
My program works flawlessly when I keep my finger on the arrow-down key for example, but once I stop nothing gets updated anymore, because that damn function doesn't return.
Any other ideas?
If this doesn't work I have to use the backup version of that program, where I wrote the UI handling myself.. badly hacked together, but at least that worked... | [reply] |
Ah, it works now!
Somehow, $cui->{-read_timeout} was -1, although it shouldn't be. So I changed it directly to 0, et voila, it doesn't wait for a key press anymore. :)
Thanks, ikegami. | [reply] |
Hi, I'm trying to do something similar to this. I am using Curses::UI to implement a ticket like system where new tickets comes in from users via UDP and it will update the Curses:UI:Listbox.
I tried to take the same route and and rather than using the $cui->mainloop(); from Curses:UI, I put it into my own server so that it can update the UI without blocking. But it seems when I do that, I lose the Curses:UI listbox functionality of having a scrollbox, being able to move up/down the list, etc; since everytime I try to run doupdate(); when a new UDP comes in, the program exits...
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use Curses::UI;
my ($sock, $data, $clienthost, $maxlen, $port);
$maxlen = 1024;
$port = 3711;
my @array;
my $cui = Curses::UI->new(-mouse_support => 0,-read_timeout => 0);
my $win = $cui->add('window_id', 'Window');
my $listbox = $win->add('Tickets', 'Listbox',
-border => 1,
-title => 'Items',
-vscrollbar => 1,
);
$cui->{-read_timeout} = 0;
$cui->set_binding( sub{ exit }, "\cQ" );
$cui->draw();
$sock = IO::Socket::INET->new(LocalPort => $port,
Type => SOCK_DGRAM,
Proto => 'udp')
or die "Could not open socket!\n";
while (1) {
$cui->focus(undef, 1); # 1 = forced focus
$sock->recv($data, $maxlen);
chomp($data);
my $req = $data;
my($port, $ipaddr) = sockaddr_in($sock->peername);
$clienthost = gethostbyaddr($ipaddr, AF_INET);
$listbox->insert_at(\@array, "New ticket from ".$clienthost.": ".$re
+q);
$sock->send("We have received your ticket: $req");
$listbox->focus();
$cui->draw;
# doupdate();
$cui->do_one_event();
| [reply] [d/l] |
... also, your description of the get_key() function said:
The default is 0 (non-blocking key read)
So no wonder that it doesn't change anything... it should have worked from the beginning on... | [reply] |
The default if nothing is passed to get_key is 0, but Curses::UI passes -1 (full blocking) by default.
By the way, I just noticed -mouse_support is 1 by default, so you'll either have to pass -mouse_support => 0 to the constructor, or do $cui->{-read_timeout} = 0 (which might break mouse support).
| [reply] [d/l] [select] |
my $cui = Curses::UI->new(
-mouse_support => 0,
-read_timeout => 0,
-color_support => 1,
-clear_on_exit => 1,
);
So that should have worked... should... :( | [reply] [d/l] |
By the way, I also cannot use add_callback( <id>, \&some_of_my_code ) and then mainloop(), because the coderef also gets run only AFTER the input handling is done. | [reply] |