circle-fe-term
view release on metacpan or search on metacpan
bin/circle-fe-term view on Meta::CPAN
#!/usr/bin/perl
# You may distribute under the terms of the GNU General Public License
#
# (C) Paul Evans, 2010-2023 -- leonerd@leonerd.org.uk
use v5.26;
use warnings;
use Tickit::Async;
use Tickit::Widget::Tabbed 0.028;
use Tickit::Widget::VBox;
use Tickit::Window 0.57; # ->bind_event
use Tickit::App::Plugin::EscapePrefix;
use Net::Async::Tangence::Client 0.15; # ->connect_url 'family' argument
use Circle::FE::Term::Tab;
use Circle::FE::Term::Ribbon;
use IO::Async::Loop;
use Text::Balanced qw( extract_bracketed );
use Getopt::Long;
my $loop = IO::Async::Loop->new();
use constant HAVE_METRICS => eval { require Metrics::Any::Adapter; };
my $IDENTITY;
my $FAMILY;
GetOptions(
'identity|i=s' => \$IDENTITY,
'metrics-port=i' => \my $METRICS_PORT,
'help' => sub { usage(0) },
'4|ipv4' => sub { $FAMILY = "inet4" },
'6|ipv6' => sub { $FAMILY = "inet6" },
) or usage(1);
sub usage
{
my ( $exitcode ) = @_;
print { $exitcode ? \*STDERR : \*STDOUT } <<'EOF';
circle-fe-term [options...] [URL]
Options:
--identity, -i IDENTITY Use the given session identity for reconnection
URL should be one of:
sshunix://host/path/to/socket
sshexec://host/path/to/command?with+arguments
exec:///path/to/command?with+arguments
tcp://host:port/
unix:///path/to/socket
EOF
exit $exitcode;
}
if( HAVE_METRICS and $METRICS_PORT ) {
Metrics::Any::Adapter->import( 'Prometheus' );
require Net::Prometheus;
Net::Prometheus->new->export_to_IO_Async( $loop, port => $METRICS_PORT );
};
my $URL = shift @ARGV or usage(1);
if( !defined $IDENTITY ) {
my $hostname = `hostname -f`; chomp $hostname;
$IDENTITY = $ENV{USER} . "@" . $hostname . "/Term";
}
my $client = Net::Async::Tangence::Client->new(
identity => $IDENTITY,
on_closed => sub {
warn "Connection closed\n";
exit(0);
},
on_error => sub { warn "Received MSG_ERROR: $_[0]\n"; },
);
$loop->add( $client );
my $rootobj = $client->connect_url( $URL, family => $FAMILY )->get;
my $t = Tickit::Async->new;
$loop->add( $t );
Tickit::App::Plugin::EscapePrefix->apply( $t );
( run in 2.050 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )