-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclienttty
61 lines (50 loc) · 1.57 KB
/
clienttty
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
58
59
60
61
// Require the lib, get a working terminal
var term = require( 'terminal-kit' ).terminal ;
const
io =require('socket.io-client'),
socket = io.connect('https://hello-lbgfrxvjkj.now.sh/', {path: '/wetty/socket.io',
extraHeaders: {
Referer: "https://hello-lbgfrxvjkj.now.sh/"
}});
term( 'The terminal size is %dx%d\n' , term.width , term.height ) ;
socket.emit('resize', {
col: term.width,
row: term.height
});
socket.on('data', function (data){
console.log(data);
socket.emit('input',{my:'data'});
});
socket.on('output', function(data) {
term(data);
});
socket.on('disconnect', function() {
term("Socket.io connection closed");
});
term.grabInput( { mouse: 'button' } ) ;
term.on( 'key' , function( key , matches , data ) {
switch ( key )
{
case 'UP' : term.up( 1 ) ; break ;
case 'DOWN' : term.down( 1 ) ; break ;
case 'LEFT' : term.left( 1 ) ; break ;
case 'RIGHT' : term.right( 1 ) ; break ;
case 'CTRL_C' : process.exit() ; break ;
default:
// Echo anything else
// term.noFormat(
// Buffer.isBuffer( data.code ) ?
// data.code :
// String.fromCharCode( data.code )
// ) ;
socket.emit('input',
Buffer.isBuffer( data.code ) ?
data.code :
String.fromCharCode( data.code )
);
break ;
}
} ) ;
term.on( 'mouse' , function( name , data ) {
term.moveTo( data.x , data.y ) ;
} ) ;