Merge pull request #477 from Tyriar/476_scrollback_update
Apply scrollback via setOption
This commit is contained in:
+6
-1
@@ -16,7 +16,12 @@
|
|||||||
<div id="terminal-container"></div>
|
<div id="terminal-container"></div>
|
||||||
<div>
|
<div>
|
||||||
<h2>Options</h2>
|
<h2>Options</h2>
|
||||||
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
|
<p>
|
||||||
|
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>Scrollback <input type="number" id="option-scrollback" value="1000" /></label>
|
||||||
|
</p>
|
||||||
<div>
|
<div>
|
||||||
<h3>Size</h3>
|
<h3>Size</h3>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
+7
-3
@@ -8,7 +8,8 @@ var term,
|
|||||||
|
|
||||||
var terminalContainer = document.getElementById('terminal-container'),
|
var terminalContainer = document.getElementById('terminal-container'),
|
||||||
optionElements = {
|
optionElements = {
|
||||||
cursorBlink: document.querySelector('#option-cursor-blink')
|
cursorBlink: document.querySelector('#option-cursor-blink'),
|
||||||
|
scrollback: document.querySelector('#option-scrollback')
|
||||||
},
|
},
|
||||||
colsElement = document.getElementById('cols'),
|
colsElement = document.getElementById('cols'),
|
||||||
rowsElement = document.getElementById('rows');
|
rowsElement = document.getElementById('rows');
|
||||||
@@ -28,6 +29,9 @@ colsElement.addEventListener('change', setTerminalSize);
|
|||||||
rowsElement.addEventListener('change', setTerminalSize);
|
rowsElement.addEventListener('change', setTerminalSize);
|
||||||
|
|
||||||
optionElements.cursorBlink.addEventListener('change', createTerminal);
|
optionElements.cursorBlink.addEventListener('change', createTerminal);
|
||||||
|
optionElements.scrollback.addEventListener('change', function () {
|
||||||
|
terminal.setOption('scrollback', parseInt(optionElements.scrollback.value, 10));
|
||||||
|
});
|
||||||
|
|
||||||
createTerminal();
|
createTerminal();
|
||||||
|
|
||||||
@@ -37,7 +41,8 @@ function createTerminal() {
|
|||||||
terminalContainer.removeChild(terminalContainer.children[0]);
|
terminalContainer.removeChild(terminalContainer.children[0]);
|
||||||
}
|
}
|
||||||
term = new Terminal({
|
term = new Terminal({
|
||||||
cursorBlink: optionElements.cursorBlink.checked
|
cursorBlink: optionElements.cursorBlink.checked,
|
||||||
|
scrollback: parseInt(optionElements.scrollback.value, 10)
|
||||||
});
|
});
|
||||||
term.on('resize', function (size) {
|
term.on('resize', function (size) {
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
@@ -78,7 +83,6 @@ function createTerminal() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function runRealTerminal() {
|
function runRealTerminal() {
|
||||||
term.attach(socket);
|
term.attach(socket);
|
||||||
term._initialized = true;
|
term._initialized = true;
|
||||||
|
|||||||
@@ -405,6 +405,24 @@ Terminal.prototype.setOption = function(key, value) {
|
|||||||
if (!(key in Terminal.defaults)) {
|
if (!(key in Terminal.defaults)) {
|
||||||
throw new Error('No option with key "' + key + '"');
|
throw new Error('No option with key "' + key + '"');
|
||||||
}
|
}
|
||||||
|
switch (key) {
|
||||||
|
case 'scrollback':
|
||||||
|
if (this.options[key] !== value) {
|
||||||
|
if (this.lines.length > value) {
|
||||||
|
const amountToTrim = this.lines.length - value;
|
||||||
|
const needsRefresh = (this.ydisp - amountToTrim < 0);
|
||||||
|
this.lines.trimStart(amountToTrim);
|
||||||
|
this.ybase = Math.max(this.ybase - amountToTrim, 0);
|
||||||
|
this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
|
||||||
|
if (needsRefresh) {
|
||||||
|
this.refresh(0, this.rows - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.lines.maxLength = value;
|
||||||
|
this.viewport.syncScrollArea();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
this[key] = value;
|
this[key] = value;
|
||||||
this.options[key] = value;
|
this.options[key] = value;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user