Merge pull request #497 from sourcelair/issue-#488-tabstopwidth

Implement configurable tab stop width
This commit is contained in:
Paris Kasidiaris
2017-01-21 01:08:23 +02:00
committed by GitHub
3 changed files with 18 additions and 8 deletions
+4 -1
View File
@@ -20,7 +20,10 @@
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label> <label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
</p> </p>
<p> <p>
<label>Scrollback <input type="number" id="option-scrollback" value="1000" /></label> <label>scrollback <input type="number" id="option-scrollback" value="1000" /></label>
</p>
<p>
<label>tabStopWidth <input type="number" id="option-tabstopwidth" value="8" /></label>
</p> </p>
<div> <div>
<h3>Size</h3> <h3>Size</h3>
+10 -5
View File
@@ -9,14 +9,15 @@ 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') scrollback: document.querySelector('#option-scrollback'),
tabstopwidth: document.querySelector('#option-tabstopwidth')
}, },
colsElement = document.getElementById('cols'), colsElement = document.getElementById('cols'),
rowsElement = document.getElementById('rows'); rowsElement = document.getElementById('rows');
function setTerminalSize () { function setTerminalSize () {
var cols = parseInt(colsElement.value), var cols = parseInt(colsElement.value, 10),
rows = parseInt(rowsElement.value), rows = parseInt(rowsElement.value, 10),
width = (cols * charWidth).toString() + 'px', width = (cols * charWidth).toString() + 'px',
height = (rows * charHeight).toString() + 'px'; height = (rows * charHeight).toString() + 'px';
@@ -32,7 +33,10 @@ optionElements.cursorBlink.addEventListener('change', function () {
term.setOption('cursorBlink', optionElements.cursorBlink.checked); term.setOption('cursorBlink', optionElements.cursorBlink.checked);
}); });
optionElements.scrollback.addEventListener('change', function () { optionElements.scrollback.addEventListener('change', function () {
terminal.setOption('scrollback', parseInt(optionElements.scrollback.value, 10)); term.setOption('scrollback', parseInt(optionElements.scrollback.value, 10));
});
optionElements.tabstopwidth.addEventListener('change', function () {
term.setOption('tabStopWidth', parseInt(optionElements.tabstopwidth.value, 10));
}); });
createTerminal(); createTerminal();
@@ -44,7 +48,8 @@ function createTerminal() {
} }
term = new Terminal({ term = new Terminal({
cursorBlink: optionElements.cursorBlink.checked, cursorBlink: optionElements.cursorBlink.checked,
scrollback: parseInt(optionElements.scrollback.value, 10) scrollback: parseInt(optionElements.scrollback.value, 10),
tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10)
}); });
term.on('resize', function (size) { term.on('resize', function (size) {
if (!pid) { if (!pid) {
+4 -2
View File
@@ -360,7 +360,8 @@ Terminal.defaults = {
screenKeys: false, screenKeys: false,
debug: false, debug: false,
cancelEvents: false, cancelEvents: false,
disableStdin: false disableStdin: false,
tabStopWidth: 8
// programFeatures: false, // programFeatures: false,
// focusKeys: false, // focusKeys: false,
}; };
@@ -433,6 +434,7 @@ Terminal.prototype.setOption = function(key, value) {
this.element.classList.toggle(`xterm-cursor-style-underline`, value === 'underline'); this.element.classList.toggle(`xterm-cursor-style-underline`, value === 'underline');
this.element.classList.toggle(`xterm-cursor-style-bar`, value === 'bar'); this.element.classList.toggle(`xterm-cursor-style-bar`, value === 'bar');
break; break;
case 'tabStopWidth': this.setupStops(); break;
} }
}; };
@@ -2118,7 +2120,7 @@ Terminal.prototype.setupStops = function(i) {
i = 0; i = 0;
} }
for (; i < this.cols; i += 8) { for (; i < this.cols; i += this.getOption('tabStopWidth')) {
this.tabs[i] = true; this.tabs[i] = true;
} }
}; };