chjj / term.js

A terminal written in javascript.
MIT License
1.55k stars 336 forks source link

dynamic #68

Open Xierip opened 9 years ago

Xierip commented 9 years ago

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();
    });
liuzheng commented 9 years ago

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

soichih commented 9 years ago

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();
scallyw4g commented 8 years ago

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 ;)