term.js icon indicating copy to clipboard operation
term.js copied to clipboard

dynamic

Open Xierip opened this issue 10 years ago • 3 comments

Hi, how i can create dynamic console (auto scale) my css is in 100% automatic, check it http://scr.hu/6gnm/hf54f && http://scr.hu/6gnm/cmryo

code:

var doc = document.getElementById('panel-body'); var term = new Terminal({ cols: (doc.clientWidth/6.36), rows: 40, useStyle: true, });

    term.on('data', function(data) {
        socket.emit('data', data);
    });
    socket.on('data', function(data) {
        term.write(data);
    });
    term.on('close', function(data) {
        console.log('konsola zamknięta');
    });
    term.open(doc || document.body);
    socket.on('disconnect', function() {
        term.destroy();
    });

Xierip avatar May 16 '15 22:05 Xierip

You can do it like this

if ($('#terminal span').length>0 && $('#terminal span')[0].children.length==0  ) {
    var boy = $('#terminal span')[0];
    var perW = boy.offsetWidth / boy.textContent.length;
    var col = Math.floor($('#terminal')[0].offsetWidth / perW);
    term.resize(30, col);
}

any question @ me

liuzheng avatar Jun 18 '15 13:06 liuzheng

Is there a way to do this without jQuery?

It would be really nice if term.js automatically calculated the row/col if no parameters were given for .resize() to fit the size of the container element.

Like. .

term.resize();

soichih avatar Sep 12 '15 00:09 soichih

If you have not figured this out already, you can do this without jQuery. Just use native JS to select the elements, the rest is the same. ie. document.getElementById("terminal");

Then submit a PR with new resize() API ;)

scallyw4g avatar Dec 23 '15 23:12 scallyw4g