Term :: Visual用于网络连接的输入和输出

时间:2016-05-16 09:19:15

标签: perl terminal cpan

我目前正在使用Perl的终端IRC客户端。因为这涉及从服务器接收数据以及用户输入和发送数据到服务器,我需要某种带有命令行的“拆分终端”和打印接收数据的窗口。

Term::Visual似乎是CPAN上最好的(也是唯一的?)模块。遗憾的是文档不是很详细,所以我尝试将上面的最小版本放在一起。它应该只打印在命令行中输入的所有内容。

我得到的只是命令提示符(我这个例子是“[foo]”)一次,之后我的bash提示符立即出现。程序似乎只是终止了。

我做错了什么?是否需要遗漏某些东西?

#!/usr/bin/perl

use strict;
use warnings;
use Term::Visual;
use POE;

my $vt = Term::Visual->new( 
                   Alias => "interface",
            Common_Input => 1,
                Errlevel => 0 );

my $window_id = $vt->create_window(
      Window_Name  => "foo",

      Buffer_Size  => 1000,
      History_Size => 50,

      Input_Prompt => "[foo] ", # Set the input prompt for the input line.

      Use_Title    => 1, # Don't use a titlebar 
      Use_Status   => 1, # Don't use a statusbar

      Title        => "Title of foo"  );

POE::Session->create
  (inline_states => {
     _start         => \&start_handler,
     got_term_input => \&term_input_handler,
   }
  );

sub start_handler {
    my $kernel = $_[KERNEL];

    # Tell the terminal to send me input as "got_term_input".
    $kernel->post( interface => send_me_input => "got_term_input" );
    $vt->set_input_prompt($window_id, "[foo]");
}

sub term_input_handler {
    my ($kernel, $heap, $input, $exception) = @_[KERNEL, HEAP, ARG0, ARG1];

    # Got an exception.  These are interrupt (^C) or quit (^\).
    if (defined $exception) {
        warn "got exception: $exception";
        exit;
    }
    $vt->print($window_id, $input);
}

POE::Session->run();
$vt->shutdown();

0 个答案:

没有答案