From ab5cc0ad05ffe1cb3aff8e91b9cb5fe3787c8631 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 16 Sep 2016 01:46:02 -0700 Subject: [PATCH 1/2] Add setOption API Fixes #271 --- src/xterm.js | 11 +++++++++++ test/test.js | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/xterm.js b/src/xterm.js index e3e04c76..b161553b 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -357,6 +357,17 @@ Terminal.prototype.focus = function() { return this.textarea.focus(); }; +/** + * Sets an option on the terminal. + */ +Terminal.prototype.setOption = function(key, value) { + if (!(key in Terminal.defaults)) { + throw new Error('No option with key "' + key + '"'); + } + this[key] = value; + this.options[key] = value; +}; + /** * Binds the desired focus behavior on a given terminal object. * diff --git a/test/test.js b/test/test.js index 91e6ddc4..4e124f9c 100644 --- a/test/test.js +++ b/test/test.js @@ -10,6 +10,20 @@ describe('xterm.js', function() { xterm.refresh = function(){}; }); + describe('setOption', function() { + it('should set the option correctly', function() { + xterm.setOption('cursorBlink', true); + assert.equal(xterm.cursorBlink, true); + assert.equal(xterm.options.cursorBlink, true); + xterm.setOption('cursorBlink', false); + assert.equal(xterm.cursorBlink, false); + assert.equal(xterm.options.cursorBlink, false); + }); + it('should throw when setting a non-existant option', function() { + assert.throws(xterm.setOption.bind(xterm, 'fake', true)); + }); + }); + describe('evaluateKeyEscapeSequence', function() { it('should return the correct escape sequence for unmodified keys', function() { // Backspace @@ -109,7 +123,7 @@ describe('xterm.js', function() { assert.equal(xterm.evaluateKeyEscapeSequence({ altKey: true, keyCode: 121 }).key, '\x1b[21;3~'); assert.equal(xterm.evaluateKeyEscapeSequence({ altKey: true, keyCode: 122 }).key, '\x1b[23;3~'); assert.equal(xterm.evaluateKeyEscapeSequence({ altKey: true, keyCode: 123 }).key, '\x1b[24;3~'); - + assert.equal(xterm.evaluateKeyEscapeSequence({ ctrlKey: true, keyCode: 112 }).key, '\x1b[1;5P'); assert.equal(xterm.evaluateKeyEscapeSequence({ ctrlKey: true, keyCode: 113 }).key, '\x1b[1;5Q'); assert.equal(xterm.evaluateKeyEscapeSequence({ ctrlKey: true, keyCode: 114 }).key, '\x1b[1;5R'); From 15e56bd809a50d23c6b3ae0459513f878d634d99 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 16 Sep 2016 02:03:31 -0700 Subject: [PATCH 2/2] Add @param to setOption --- src/xterm.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index b161553b..f4b8d453 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -359,6 +359,8 @@ Terminal.prototype.focus = function() { /** * Sets an option on the terminal. + * @param {string} key The option key. + * @param {string} value The option value. */ Terminal.prototype.setOption = function(key, value) { if (!(key in Terminal.defaults)) {