diff --git a/src/addons/attach/attach.ts b/src/addons/attach/attach.ts index 0142c35e..4827e070 100644 --- a/src/addons/attach/attach.ts +++ b/src/addons/attach/attach.ts @@ -16,7 +16,7 @@ * should happen instantly or at a maximum * 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; term.socket = socket; @@ -79,7 +79,7 @@ function attach(term, socket, bidirectional, buffered) { * @param {WebSocket} socket - The socket from which to detach the current * terminal. */ -function detach(term, socket) { +export function detach(term, socket) { term.off('data', term._sendData); socket = (typeof socket == 'undefined') ? term.socket : socket; diff --git a/src/addons/fit/fit.ts b/src/addons/fit/fit.ts index a372d0bb..ebd0177a 100644 --- a/src/addons/fit/fit.ts +++ b/src/addons/fit/fit.ts @@ -13,7 +13,7 @@ * row and truncate its width with the current number of columns). */ -function proposeGeometry(term) { +export function proposeGeometry(term) { if (!term.element.parentElement) { return null; } @@ -33,7 +33,7 @@ function proposeGeometry(term) { return geometry; }; -function fit(term) { +export function fit(term) { // Wrap fit in a setTimeout as charMeasure needs time to get initialized // after calling Terminal.open setTimeout(function () { diff --git a/src/addons/fullscreen/fullscreen.ts b/src/addons/fullscreen/fullscreen.ts index 7211b518..31ab5189 100644 --- a/src/addons/fullscreen/fullscreen.ts +++ b/src/addons/fullscreen/fullscreen.ts @@ -8,7 +8,7 @@ * @param {Terminal} term - The terminal to toggle full screen mode * @param {boolean} fullscreen - Toggle fullscreen on (true) or off (false) */ -function toggleFullScreen(term, fullscreen) { +export function toggleFullScreen(term, fullscreen) { var fn; if (typeof fullscreen == 'undefined') { diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 69c5737b..aae0e392 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -4,54 +4,41 @@ */ 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) { - /** - * Plain browser environment - */ - addon(window.Terminal); - } else if (typeof exports === 'object' && typeof module === 'object') { - /** - * CommonJS environment - */ - module.exports = addon(require('../../Terminal').Terminal); - } else if (typeof define === 'function') { - /** - * Require.js is available - */ - define(['../../xterm'], addon); +/** + * 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. + */ +function findNext(terminal: ITerminal, term: string): boolean { + if (!terminal._searchHelper) { + terminal.searchHelper = new SearchHelper(terminal); } -})((Terminal: any) => { - /** - * 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 (this.searchHelper).findNext(term); - }; + return (terminal.searchHelper).findNext(term); +}; - /** - * Find the previous 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.findPrevious = function(term: string): boolean { - if (!this._searchHelper) { - this.searchHelper = new SearchHelper(this); - } - return (this.searchHelper).findPrevious(term); - }; -}); +/** + * Find the previous 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.findPrevious = function(terminal: ITerminal, term: string): boolean { + if (!terminal._searchHelper) { + terminal.searchHelper = new SearchHelper(terminal); + } + return (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); + } +} diff --git a/src/addons/terminado/terminado.ts b/src/addons/terminado/terminado.ts index 50bec2e8..9a7c7ad6 100644 --- a/src/addons/terminado/terminado.ts +++ b/src/addons/terminado/terminado.ts @@ -17,7 +17,7 @@ * should happen instantly or at a maximum * 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; term.socket = socket; @@ -72,7 +72,7 @@ function terminadoAttach(term, socket, bidirectional, buffered) { * @param {WebSocket} socket - The socket from which to detach the current * terminal. */ -function terminadoDetach(term, socket) { +export function terminadoDetach(term, socket) { term.off('data', term._sendData); socket = (typeof socket == 'undefined') ? term.socket : socket; diff --git a/src/addons/winptyCompat/winptyCompat.ts b/src/addons/winptyCompat/winptyCompat.ts index c9e9a53a..9dc46e46 100644 --- a/src/addons/winptyCompat/winptyCompat.ts +++ b/src/addons/winptyCompat/winptyCompat.ts @@ -3,8 +3,7 @@ * @license MIT */ -export function apply(terminalConstructor) { - terminalConstructor.prototype.winptyCompatInit = function(): void { +export function winptyCompatInit(terminal): void { // Don't do anything when the platform is not Windows const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0; if (!isWindows) { @@ -21,13 +20,18 @@ export function apply(terminalConstructor) { // 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 // wrapped. - this.on('lineFeed', () => { - const line = this.buffer.lines.get(this.buffer.ybase + this.buffer.y - 1); - const lastChar = line[this.cols - 1]; + terminal.on('lineFeed', () => { + const line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1); + const lastChar = line[terminal.cols - 1]; + 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); (nextLine).isWrapped = true; } }); + +export function apply(terminalConstructor) { + terminalConstructor.prototype.winptyCompatInit = function(): void { + winptyCompatInit(this); }; }