Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ <h1>xterm.js: xterm, in the browser</h1>
<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>
Expand Down
10 changes: 7 additions & 3 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();

Expand All @@ -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) {
Expand Down Expand Up @@ -78,7 +83,6 @@ function createTerminal() {
});
}


function runRealTerminal() {
term.attach(socket);
term._initialized = true;
Expand Down
18 changes: 18 additions & 0 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down