#!/usr/bin/perl use strict; use Net::Telnet qw(TELOPT_TTYPE); use HTML::FromANSI; $| = 1; my ($host, $port) = ('localhost', 23); my $t = new Net::Telnet ( 'Host' => $host, 'Port' => $port, 'Errmode' => 'return', 'Timeout' => 1, 'Output_record_separator' => '', ); die "failed to connect to $host:$port" if (not defined $t); $t->option_callback (\&opt_callback); $t->option_accept ('Do' => TELOPT_TTYPE); $t->suboption_callback (\&subopt_callback); my $vt = Term::VT102->new( rows => 24, cols => 80 ); my $html_vt = HTML::FromANSI->new( terminal_object => $term ); # Convert linefeeds to linefeed + carriage return. # $vt->option_set ('LFTOCRLF', 1); # Make sure line wrapping is switched on. # $vt->option_set ('LINEWRAP', 1); # Set up the callback for OUTPUT; this callback function simply sends # whatever the Term::VT102 module wants to send back to the terminal and # sends it to Net::Telnet - see its definition below. # $vt->callback_set ('OUTPUT', \&vt_output, $t); # Callback for "DO" handling - for Net::Telnet. # sub opt_callback { my ($obj,$opt,$is_remote,$is_enabled,$was_enabled,$buf_position) = @_; if ($opt == TELOPT_TTYPE and $is_enabled and !$is_remote) { # # Perhaps do something if we get TELOPT_TTYPE switched on? # } return 1; } # Callback for sub-option handling - for Net::Telnet. # sub subopt_callback { my ($obj, $opt, $parameters) = @_; my ($ors_old, $otm_old); # Respond to TELOPT_TTYPE with "I'm a VT102". # if ($opt == TELOPT_TTYPE) { $ors_old = $obj->output_record_separator (''); $otm_old = $obj->telnetmode (0); $obj->print ( "\xff\xfa", pack ('CC', $opt, 0), 'vt102', "\xff\xf0" ); $obj->telnetmode ($otm_old); $obj->output_record_separator ($ors_old); } return 1; } # Callback for OUTPUT events - for Term::VT102. # sub vt_output { my ($vtobject, $type, $arg1, $arg2, $private) = @_; if ($type eq 'OUTPUT') { $private->print ($arg1); } }