Author: nornagon
Date: 2005-01-01 04:37:27 -0500 (Sat, 01 Jan 2005)
New Revision: 508
Modified:
trunk/clients/termvisual/termvisual.pl
Log:
Tab completion in Term::Visual client complete. Some errors/warnings fixed.
Modified: trunk/clients/termvisual/termvisual.pl
===================================================================
--- trunk/clients/termvisual/termvisual.pl 2005-01-01 09:34:31 UTC (rev
507)
+++ trunk/clients/termvisual/termvisual.pl 2005-01-01 09:37:27 UTC (rev
508)
@@ -11,7 +11,7 @@
use POE;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
-use POE::Filter::Haver;
+use Haver::Protocol::Filter;
use Socket;
use Term::Visual;
@@ -22,6 +22,20 @@
my (%ucommands, %scommands);
+my $config_handle = Haver::Config->new(
+ file => "config",
+ default => {
+ UID => Haver::OS->current_user,
+ Channel => 'lobby',
+ HistSize => 50,
+ BufferSize => 1000,
+ Server => 'localhost',
+ Port => '7070',
+ CommandChars => '/.',
+ },
+);
+my $config = $config_handle->config;
+
my %palette = (
channel => 'bright cyan on black',
nick => 'white on black',
@@ -53,21 +67,6 @@
sub handle_start {
my ($kernel, $heap) = @_[KERNEL, HEAP];
- $heap->{config_handle} = Haver::Config->new(
- file => "config",
- default => {
- UID => Haver::OS->current_user,
- Channel => 'lobby',
- HistSize => 50,
- BufferSize => 1000,
- Server => 'localhost',
- Port => '7070',
- CommandChars => '/.',
- },
- );
- $heap->{config} = $heap->{config_handle}->config;
- $heap->{config}{CommandChars} = '/.';
-
$heap->{vt} = Term::Visual->new(
Alias => "user_interface",
Common_Input => 1,
@@ -81,8 +80,8 @@
Status => { 0 => { format => "Server: %s",
fields => [qw(server)] },
},
- Buffer_Size => $heap->{config}{BufferSize},
- History_Size => $heap->{config}{HistSize},
+ Buffer_Size => $config->{BufferSize},
+ History_Size => $config->{HistSize},
Status_Height => 1,
Title => "Haver"
);
@@ -98,7 +97,7 @@
sub handle_shutdown {
my ($kernel, $heap) = @_[KERNEL, HEAP];
- $heap->{config_handle}->save;
+ $config_handle->save;
$heap->{vt}->delete_window($heap->{window_id});
$heap->{vt}->shutdown;
exit;
@@ -116,7 +115,7 @@
# Handle user commands.
# A command character followed directly by some text equates a command.
# Eg: /quit; .connect
- if ($input =~ /^\s*[$heap->{config}{CommandChars}](.+)$/x) {
+ if ($input =~ /^\s*[$config->{CommandChars}](.+)$/x) {
my @input = split / /, $1;
if (exists $ucommands{$input[0]}) {
my $cmd = shift @input;
@@ -140,11 +139,11 @@
Handle => $socket,
InputEvent => 'socket_input',
ErrorEvent => 'socket_error',
- Filter => new POE::Filter::Haver,
+ Filter => new Haver::Protocol::Filter,
);
$heap->{vt}->set_status_field($heap->{window_id},
- server => $heap->{config}{Server});
+ server => $config->{Server});
$heap->{socket}->put(['HAVER', 'Term::Visual/0.01']);
}
@@ -192,7 +191,7 @@
my $heap = $poe_kernel->get_active_session()->get_heap();
my ($want) = $_[0];
if ($want eq 'IDENT') {
- $heap->{socket}->put(['IDENT', $heap->{config}{UID}]);
+ $heap->{socket}->put(['IDENT', $config->{UID}]);
} else {
vt_print("Unhandlable WANT: $want");
$heap->{socket}->put(['CANT', $want]);
@@ -209,7 +208,7 @@
my ($command, $errorcode, @args) = @_;
vt_print("$command failed: $errorcode");
if ($command eq 'IDENT') {
- $heap->{config}{UID} .= '_';
+ $config->{UID} .= '_';
}
}
@@ -298,16 +297,16 @@
$port = 7070 if (!defined $port && defined $server);
if (defined $server) {
- $heap->{config}{Server} = $server;
- $heap->{config}{Port} = $port;
+ $config->{Server} = $server;
+ $config->{Port} = $port;
}
$heap->{vt}->print($heap->{window_id},
- "Connecting to $heap->{config}{Server}:$heap->{config}{Port}...");
+ "Connecting to $config->{Server}:$config->{Port}...");
$heap->{socketfactory} = POE::Wheel::SocketFactory->new(
- RemoteAddress => $heap->{config}{Server},
- RemotePort => $heap->{config}{Port},
+ RemoteAddress => $config->{Server},
+ RemotePort => $config->{Port},
SuccessEvent => 'socket_connected',
FailureEvent => 'socket_error',
);
@@ -315,7 +314,7 @@
sub command_save {
my $heap = $poe_kernel->get_active_session()->get_heap();
- $heap->{config}->save;
+ $config_handle->save;
$heap->{vt}->print($heap->{window_id}, "Configuration saved.");
}
@@ -378,8 +377,7 @@
# Misc functions
sub vt_print {
- my $heap = get_heap();
- $heap->{vt}->print($heap->{window_id}, @_);
+ get_heap()->{vt}->print(get_heap()->{window_id}, @_);
}
sub chan_msg {
@@ -394,18 +392,12 @@
sub tab_complete {
my $left = shift;
- my $heap = get_heap();
- my $cc = $heap->{config}{CommandChars};
- if ($cc ne '/.') { return $cc; }
- return;
- $left =~ /^[$cc]/;
- return;
# return if it's not a command
- if (!($left =~ /^[$heap->{config}{CommandChars}]/)) { vt_print("b"); }
- return;
- $left =~ s/^[$heap->{config}{CommandChars}]//;
+ if (!($left =~ /^[$config->{CommandChars}]/)) { vt_print("b"); }
+ $left =~ s/^([$config->{CommandChars}])//;
my @ret = grep { /^$left/ } keys %ucommands;
-# return @ret;
+ @ret = map { $_ = $1.$_.' ' } @ret;
+ return @ret;
}
POE::Kernel->run();