Stupid xterm

This commit is contained in:
BuildTools 2019-09-03 16:11:23 +02:00
parent 2f18843893
commit f9d7bc89b0
2 changed files with 44 additions and 22 deletions

View File

@ -11,9 +11,14 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style> <style>
body { body {
height: 100vh!important;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
div#terminal {
height: 100%;
width: 100%;
}
</style> </style>
</head> </head>
<body> <body>
@ -22,10 +27,20 @@
</div> </div>
<script> <script>
var term = new Terminal(); var term = new Terminal();
term.open(document.getElementById('terminal'))
// Connect to the socket.io server // Connect to the socket.io server
var socket = io.connect('http://localhost:9774'); var socket = io.connect('http://localhost:9774');
// Wait for data from the server // 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) { socket.on('output', function (data) {
term.write(data); term.write(data);
}); });

11
main.js
View File

@ -24,11 +24,17 @@ var io = require('socket.io')(server);
// When a new socket connects // When a new socket connects
io.on('connection', function (socket) { io.on('connection', function (socket) {
console.log('Client connect'); console.log('Client connect');
socket.emit('client_identify');
socket.on('client_size', function (size) {
// Create terminal // Create terminal
console.log(size);
console.log({ cols: Math.floor(size.width / 9), rows: Math.floor(size.height / 10) })
var term = pty.spawn('sh', [], { var term = pty.spawn('sh', [], {
name: 'xterm-color', name: 'xterm-color',
cols: 80, cols: Math.floor(size.width / 9),
rows: 30, rows: Math.floor(size.height / 10),
cwd: process.env.HOME, cwd: process.env.HOME,
env: process.env env: process.env
}); });
@ -45,4 +51,5 @@ io.on('connection', function (socket) {
term.destroy(); term.destroy();
console.log("Client disconnect"); console.log("Client disconnect");
}); });
})
}); });