-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTerminal
executable file
·57 lines (43 loc) · 1.29 KB
/
Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env perl
use lib './lib';
use Mojolicious::Lite;
use Terminal;
use IO::File;
get '/' => sub {
my $self = shift;
$self->render( template => 'index' );
};
websocket '/socket' => sub {
my $self = shift;
Mojo::IOLoop->stream( $self->tx->connection )->timeout(0);
my $terminal = Terminal->new( cmd => '/bin/bash', app => $self->app );
$terminal->on(
row_changed => sub {
my ( $event, $message ) = @_;
$self->send(
{ json => { stdout => $message, type => 'terminal' } } );
}
);
$self->on(
json => sub {
my ( $self, $message ) = @_;
if ( exists $message->{'screen'} ) {
my $screen = $message->{'screen'};
$self->app->log->debug(
"setting screen size to $screen->{'rows'} X $screen->{'cols'}"
);
$terminal->resize( $screen->{'rows'}, $screen->{'cols'} );
}
$terminal->write( $message->{'stdin'} )
if exists $message->{'stdin'};
}
);
$self->on(
finish => sub {
$self->app->log->debug('Client disconnected');
$terminal->cleanup();
}
);
$terminal->start() unless $terminal->is_spawned;
};
app->start;