From 4b459fe0fdef55d42a60717dd372bf882930df53 Mon Sep 17 00:00:00 2001 From: Paris Kasidiaris Date: Wed, 21 Sep 2016 13:56:03 +0300 Subject: [PATCH] Implement `term.getOption` --- src/xterm.js | 16 ++++++++++++++++ test/test.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index 08386be3..f785ab1a 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -357,6 +357,22 @@ Terminal.prototype.focus = function() { return this.textarea.focus(); }; +/** + * Retrieves an option's value from the terminal. + * @param {string} key The option key. + */ +Terminal.prototype.getOption = function(key, value) { + if (!(key in Terminal.defaults)) { + throw new Error('No option with key "' + key + '"'); + } + + if (typeof this.options[key] != 'undefined') { + return this.options[key]; + } + + return this[key]; +}; + /** * Sets an option on the terminal. * @param {string} key The option key. diff --git a/test/test.js b/test/test.js index 043906f6..77caad08 100644 --- a/test/test.js +++ b/test/test.js @@ -10,6 +10,22 @@ describe('xterm.js', function() { xterm.refresh = function(){}; }); + describe('getOption', function() { + it('should retrieve the option correctly', function() { + // In the `options` namespace. + xterm.options.cursorBlink = true; + assert.equal(xterm.getOption('cursorBlink'), true); + + // On the Terminal instance + delete xterm.options.cursorBlink; + xterm.cursorBlink = false; + assert.equal(xterm.getOption('cursorBlink'), false); + }); + it('should throw when retrieving a non-existant option', function() { + assert.throws(xterm.getOption.bind(xterm, 'fake', true)); + }); + }); + describe('setOption', function() { it('should set the option correctly', function() { xterm.setOption('cursorBlink', true);