mirror of
https://github.com/nuintun/command-manager.git
synced 2025-12-16 07:36:08 +08:00
update files
This commit is contained in:
94
static/js/terminal/lib/resize.js
Normal file
94
static/js/terminal/lib/resize.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Created by nuintun on 2015/11/25.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
Terminal.prototype.resize = function (x, y){
|
||||
var line, element, i, j, ch;
|
||||
|
||||
if (x < 1) x = 1;
|
||||
|
||||
if (y < 1) y = 1;
|
||||
|
||||
// resize cols
|
||||
j = this.cols;
|
||||
|
||||
if (j < x) {
|
||||
// does xterm use the default attr
|
||||
ch = [this.defAttr, ' '];
|
||||
i = this.lines.length;
|
||||
|
||||
while (i--) {
|
||||
while (this.lines[i].length < x) {
|
||||
this.lines[i].push(ch);
|
||||
}
|
||||
}
|
||||
} else if (j > x) {
|
||||
i = this.lines.length;
|
||||
|
||||
while (i--) {
|
||||
while (this.lines[i].length > x) {
|
||||
this.lines[i].pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setupStops(j);
|
||||
|
||||
this.cols = x;
|
||||
|
||||
// resize rows
|
||||
j = this.rows;
|
||||
|
||||
if (j < y) {
|
||||
element = this.element;
|
||||
while (j++ < y) {
|
||||
if (this.lines.length < y + this.ybase) {
|
||||
this.lines.push(this.blankLine());
|
||||
}
|
||||
|
||||
if (this.children.length < y) {
|
||||
line = this.document.createElement('div');
|
||||
|
||||
element.appendChild(line);
|
||||
|
||||
this.children.push(line);
|
||||
}
|
||||
}
|
||||
} else if (j > y) {
|
||||
while (j-- > y) {
|
||||
if (this.lines.length > y + this.ybase) {
|
||||
this.lines.pop();
|
||||
}
|
||||
|
||||
if (this.children.length > y) {
|
||||
element = this.children.pop();
|
||||
|
||||
if (!element) continue;
|
||||
|
||||
element.parentNode.removeChild(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.rows = y;
|
||||
|
||||
// make sure the cursor stays on screen
|
||||
if (this.y >= y) this.y = y - 1;
|
||||
|
||||
if (this.x >= x) this.x = x - 1;
|
||||
|
||||
this.scrollTop = 0;
|
||||
this.scrollBottom = y - 1;
|
||||
|
||||
this.refresh(0, this.rows - 1);
|
||||
|
||||
// it's a real nightmare trying
|
||||
// to resize the original
|
||||
// screen buffer. just set it
|
||||
// to null for now.
|
||||
this.normal = null;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user