Export static methods wherever possible

This commit is contained in:
Paris Kasidiaris
2017-12-12 08:46:06 +00:00
parent 052dc15d55
commit d81e304ce7
6 changed files with 51 additions and 60 deletions
+2 -2
View File
@@ -16,7 +16,7 @@
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
function attach(term, socket, bidirectional, buffered) { export function attach(term, socket, bidirectional, buffered) {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
term.socket = socket; term.socket = socket;
@@ -79,7 +79,7 @@ function attach(term, socket, bidirectional, buffered) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
function detach(term, socket) { export function detach(term, socket) {
term.off('data', term._sendData); term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket; socket = (typeof socket == 'undefined') ? term.socket : socket;
+2 -2
View File
@@ -13,7 +13,7 @@
* row and truncate its width with the current number of columns). * row and truncate its width with the current number of columns).
*/ */
function proposeGeometry(term) { export function proposeGeometry(term) {
if (!term.element.parentElement) { if (!term.element.parentElement) {
return null; return null;
} }
@@ -33,7 +33,7 @@ function proposeGeometry(term) {
return geometry; return geometry;
}; };
function fit(term) { export function fit(term) {
// Wrap fit in a setTimeout as charMeasure needs time to get initialized // Wrap fit in a setTimeout as charMeasure needs time to get initialized
// after calling Terminal.open // after calling Terminal.open
setTimeout(function () { setTimeout(function () {
+1 -1
View File
@@ -8,7 +8,7 @@
* @param {Terminal} term - The terminal to toggle full screen mode * @param {Terminal} term - The terminal to toggle full screen mode
* @param {boolean} fullscreen - Toggle fullscreen on (true) or off (false) * @param {boolean} fullscreen - Toggle fullscreen on (true) or off (false)
*/ */
function toggleFullScreen(term, fullscreen) { export function toggleFullScreen(term, fullscreen) {
var fn; var fn;
if (typeof fullscreen == 'undefined') { if (typeof fullscreen == 'undefined') {
+34 -47
View File
@@ -4,54 +4,41 @@
*/ */
import { SearchHelper } from './SearchHelper'; import { SearchHelper } from './SearchHelper';
import { ITerminal } from '../../Interfaces';
declare var exports: any;
declare var module: any;
declare var define: any;
declare var require: any;
declare var window: any;
(function (addon) { /**
if (typeof window !== 'undefined' && 'Terminal' in window) { * Find the next instance of the term, then scroll to and select it. If it
/** * doesn't exist, do nothing.
* Plain browser environment * @param term Tne search term.
*/ * @return Whether a result was found.
addon(window.Terminal); */
} else if (typeof exports === 'object' && typeof module === 'object') { function findNext(terminal: ITerminal, term: string): boolean {
/** if (!terminal._searchHelper) {
* CommonJS environment terminal.searchHelper = new SearchHelper(terminal);
*/
module.exports = addon(require('../../Terminal').Terminal);
} else if (typeof define === 'function') {
/**
* Require.js is available
*/
define(['../../xterm'], addon);
} }
})((Terminal: any) => { return (<SearchHelper>terminal.searchHelper).findNext(term);
/** };
* Find the next instance of the term, then scroll to and select it. If it
* doesn't exist, do nothing.
* @param term Tne search term.
* @return Whether a result was found.
*/
Terminal.prototype.findNext = function(term: string): boolean {
if (!this._searchHelper) {
this.searchHelper = new SearchHelper(this);
}
return (<SearchHelper>this.searchHelper).findNext(term);
};
/** /**
* Find the previous instance of the term, then scroll to and select it. If it * Find the previous instance of the term, then scroll to and select it. If it
* doesn't exist, do nothing. * doesn't exist, do nothing.
* @param term Tne search term. * @param term Tne search term.
* @return Whether a result was found. * @return Whether a result was found.
*/ */
Terminal.prototype.findPrevious = function(term: string): boolean { Terminal.prototype.findPrevious = function(terminal: ITerminal, term: string): boolean {
if (!this._searchHelper) { if (!terminal._searchHelper) {
this.searchHelper = new SearchHelper(this); terminal.searchHelper = new SearchHelper(terminal);
} }
return (<SearchHelper>this.searchHelper).findPrevious(term); return (<SearchHelper>terminal.searchHelper).findPrevious(term);
}; };
});
export function apply(terminalConstructor) {
terminalConstructor.prototype.findNext = function(term) {
return findNext(this, term);
}
terminalConstructor.prototype.findPrevious = function(term) {
return findPrevious(this, term);
}
}
+2 -2
View File
@@ -17,7 +17,7 @@
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
function terminadoAttach(term, socket, bidirectional, buffered) { export function terminadoAttach(term, socket, bidirectional, buffered) {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
term.socket = socket; term.socket = socket;
@@ -72,7 +72,7 @@ function terminadoAttach(term, socket, bidirectional, buffered) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
function terminadoDetach(term, socket) { export function terminadoDetach(term, socket) {
term.off('data', term._sendData); term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket; socket = (typeof socket == 'undefined') ? term.socket : socket;
+10 -6
View File
@@ -3,8 +3,7 @@
* @license MIT * @license MIT
*/ */
export function apply(terminalConstructor) { export function winptyCompatInit(terminal): void {
terminalConstructor.prototype.winptyCompatInit = function(): void {
// Don't do anything when the platform is not Windows // Don't do anything when the platform is not Windows
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0; const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0;
if (!isWindows) { if (!isWindows) {
@@ -21,13 +20,18 @@ export function apply(terminalConstructor) {
// space. This is certainly not without its problems, but generally on // space. This is certainly not without its problems, but generally on
// Windows when text reaches the end of the terminal it's likely going to be // Windows when text reaches the end of the terminal it's likely going to be
// wrapped. // wrapped.
this.on('lineFeed', () => { terminal.on('lineFeed', () => {
const line = this.buffer.lines.get(this.buffer.ybase + this.buffer.y - 1); const line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1);
const lastChar = line[this.cols - 1]; const lastChar = line[terminal.cols - 1];
if (lastChar[3] !== 32 /* ' ' */) { if (lastChar[3] !== 32 /* ' ' */) {
const nextLine = this.buffer.lines.get(this.buffer.ybase + this.buffer.y); const nextLine = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y);
(<any>nextLine).isWrapped = true; (<any>nextLine).isWrapped = true;
} }
}); });
export function apply(terminalConstructor) {
terminalConstructor.prototype.winptyCompatInit = function(): void {
winptyCompatInit(this);
}; };
} }