Stupid xterm
This commit is contained in:
parent
2f18843893
commit
f9d7bc89b0
17
index.html
17
index.html
@ -11,9 +11,14 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
height: 100vh!important;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
div#terminal {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -22,10 +27,20 @@
|
||||
</div>
|
||||
<script>
|
||||
var term = new Terminal();
|
||||
term.open(document.getElementById('terminal'))
|
||||
|
||||
// Connect to the socket.io server
|
||||
var socket = io.connect('http://localhost:9774');
|
||||
// Wait for data from the server
|
||||
socket.on('client_identify', function() {
|
||||
var size = {
|
||||
height: document.querySelector('body').offsetHeight,
|
||||
width: document.querySelector('body').offsetWidth,
|
||||
}
|
||||
socket.emit('client_size', size)
|
||||
});
|
||||
|
||||
term.open(document.getElementById('terminal'))
|
||||
|
||||
socket.on('output', function (data) {
|
||||
term.write(data);
|
||||
});
|
||||
|
11
main.js
11
main.js
@ -24,11 +24,17 @@ var io = require('socket.io')(server);
|
||||
// When a new socket connects
|
||||
io.on('connection', function (socket) {
|
||||
console.log('Client connect');
|
||||
socket.emit('client_identify');
|
||||
|
||||
socket.on('client_size', function (size) {
|
||||
// Create terminal
|
||||
console.log(size);
|
||||
console.log({ cols: Math.floor(size.width / 9), rows: Math.floor(size.height / 10) })
|
||||
|
||||
var term = pty.spawn('sh', [], {
|
||||
name: 'xterm-color',
|
||||
cols: 80,
|
||||
rows: 30,
|
||||
cols: Math.floor(size.width / 9),
|
||||
rows: Math.floor(size.height / 10),
|
||||
cwd: process.env.HOME,
|
||||
env: process.env
|
||||
});
|
||||
@ -45,4 +51,5 @@ io.on('connection', function (socket) {
|
||||
term.destroy();
|
||||
console.log("Client disconnect");
|
||||
});
|
||||
})
|
||||
});
|
Loading…
Reference in New Issue
Block a user