mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-11-02 22:07:41 +00:00
Merge pull request #477 from Tyriar/476_scrollback_update
Apply scrollback via setOption
This commit is contained in:
commit
3422f84e00
@ -16,7 +16,12 @@
|
||||
<div id="terminal-container"></div>
|
||||
<div>
|
||||
<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>
|
||||
<h3>Size</h3>
|
||||
<div>
|
||||
|
||||
10
demo/main.js
10
demo/main.js
@ -8,7 +8,8 @@ var term,
|
||||
|
||||
var terminalContainer = document.getElementById('terminal-container'),
|
||||
optionElements = {
|
||||
cursorBlink: document.querySelector('#option-cursor-blink')
|
||||
cursorBlink: document.querySelector('#option-cursor-blink'),
|
||||
scrollback: document.querySelector('#option-scrollback')
|
||||
},
|
||||
colsElement = document.getElementById('cols'),
|
||||
rowsElement = document.getElementById('rows');
|
||||
@ -28,6 +29,9 @@ colsElement.addEventListener('change', setTerminalSize);
|
||||
rowsElement.addEventListener('change', setTerminalSize);
|
||||
|
||||
optionElements.cursorBlink.addEventListener('change', createTerminal);
|
||||
optionElements.scrollback.addEventListener('change', function () {
|
||||
terminal.setOption('scrollback', parseInt(optionElements.scrollback.value, 10));
|
||||
});
|
||||
|
||||
createTerminal();
|
||||
|
||||
@ -37,7 +41,8 @@ function createTerminal() {
|
||||
terminalContainer.removeChild(terminalContainer.children[0]);
|
||||
}
|
||||
term = new Terminal({
|
||||
cursorBlink: optionElements.cursorBlink.checked
|
||||
cursorBlink: optionElements.cursorBlink.checked,
|
||||
scrollback: parseInt(optionElements.scrollback.value, 10)
|
||||
});
|
||||
term.on('resize', function (size) {
|
||||
if (!pid) {
|
||||
@ -78,7 +83,6 @@ function createTerminal() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function runRealTerminal() {
|
||||
term.attach(socket);
|
||||
term._initialized = true;
|
||||
|
||||
18
src/xterm.js
18
src/xterm.js
@ -405,6 +405,24 @@ Terminal.prototype.setOption = function(key, value) {
|
||||
if (!(key in Terminal.defaults)) {
|
||||
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.options[key] = value;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user