From a0ce9a79a9daf8bca5038d68be46ec8f8bdb35b9 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 7 Aug 2017 23:14:14 -0700 Subject: [PATCH 1/3] Build and export TS declaration files Fixes #866 --- gulpfile.js | 5 ++++- package.json | 5 ++++- src/Parser.ts | 2 +- tsconfig.json | 4 ++-- typings.json | 6 ------ 5 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 typings.json diff --git a/gulpfile.js b/gulpfile.js index 6e211023..72c74651 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -39,7 +39,10 @@ gulp.task('tsc', function () { // Build all TypeScript files (including tests) to ${outDir}/, based on the configuration defined in // `tsconfig.json`. let tsResult = tsProject.src().pipe(sourcemaps.init()).pipe(tsProject()); - let tsc = tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest(outDir)); + let tsc = merge( + tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest(outDir)), + tsResult.dts.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest(outDir)) + ); fs.emptyDirSync(`${outDir}/addons/search`); let tsResultSearchAddon = tsProjectSearchAddon.src().pipe(sourcemaps.init()).pipe(tsProjectSearchAddon()); diff --git a/package.json b/package.json index d0ba5c01..a5f0bd75 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test", ".gitignore" ], - "main": "lib/xterm.js", + "main": "lib/Terminal.js", + "types": "lib/Terminal.d.ts", "repository": "https://github.com/sourcelair/xterm.js", "license": "MIT", "files": [ @@ -21,8 +22,10 @@ "dist/**/*.js.map", "lib/*.css", "lib/**/*.css", + "lib/*.d.ts", "lib/*.js", "lib/*.js.map", + "lib/**/*.d.ts", "lib/**/*.js", "lib/**/*.js.map", "src/*.css", diff --git a/src/Parser.ts b/src/Parser.ts index 90d413a7..3f05992b 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -148,7 +148,7 @@ csiStateHandler['s'] = (handler, params) => handler.saveCursor(params); csiStateHandler['u'] = (handler, params) => handler.restoreCursor(params); csiStateHandler[C0.CAN] = (handler, params, prefix, postfix, parser) => parser.setState(ParserState.NORMAL); -enum ParserState { +export enum ParserState { NORMAL = 0, ESCAPED = 1, CSI_PARAM = 2, diff --git a/tsconfig.json b/tsconfig.json index 2e9703dd..a3aa790c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "module": "commonjs", "target": "es5", "rootDir": "src", - "allowJs": true, "outDir": "lib", "sourceMap": true, - "removeComments": true + "removeComments": true, + "declaration": true }, "include": [ "src/**/*" diff --git a/typings.json b/typings.json deleted file mode 100644 index 8210c007..00000000 --- a/typings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "xterm", - "globalDependencies": { - "node": "registry:env/node#6.0.0+20160918225031" - } -} From 3b787824d37280a8e8e03c3df3b8be513173880b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 8 Aug 2017 00:08:04 -0700 Subject: [PATCH 2/3] Fix import for CommonJS consumers CommonJS now imports the Terminal object directly as the trick in xterm.ts wasn't working properly. Fixes #865 --- README.md | 12 ++++++++++++ src/Terminal.ts | 9 +++++++++ src/addons/attach/attach.js | 12 ++++++------ src/addons/fit/fit.js | 8 ++++---- src/addons/fullscreen/fullscreen.js | 8 ++++---- src/addons/search/search.ts | 2 +- src/addons/terminado/terminado.js | 10 +++++----- src/handlers/Clipboard.test.ts | 2 +- src/xterm.ts | 13 ++----------- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 5a5f8e51..e1217bcd 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,18 @@ var xterm = new Terminal(); xterm.fit(); ``` +## CommonJS + +Importing xterm.js in a CommonJS environment (eg. [Electron](https://electron.atom.io/)) can be done like so: + +```ts +// JavaScript +var Terminal = require('xterm').Terminal; + +// TypeScript +import { Terminal } from 'xterm'; +``` + ## Releases Xterm.js follows a monthly release cycle roughly. diff --git a/src/Terminal.ts b/src/Terminal.ts index 31eaef8a..d8e88b2d 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -8,6 +8,15 @@ * has been extended to include xterm CSI codes, among * other features. * @license MIT + * + * Terminal Emulation References: + * http://vt100.net/ + * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt + * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + * http://invisible-island.net/vttest/ + * http://www.inwap.com/pdp10/ansicode.txt + * http://linux.die.net/man/4/console_codes + * http://linux.die.net/man/7/urxvt */ import { BufferSet } from './BufferSet'; diff --git a/src/addons/attach/attach.js b/src/addons/attach/attach.js index c2a7989b..34dc4f68 100644 --- a/src/addons/attach/attach.js +++ b/src/addons/attach/attach.js @@ -9,7 +9,7 @@ /* * CommonJS environment */ - module.exports = attach(require('../../xterm')); + module.exports = attach(require('../../Terminal').Terminal); } else if (typeof define == 'function') { /* * Require.js is available @@ -21,7 +21,7 @@ */ attach(window.Terminal); } -})(function (Xterm) { +})(function (Terminal) { 'use strict'; var exports = {}; @@ -29,7 +29,7 @@ /** * Attaches the given terminal to the given socket. * - * @param {Xterm} term - The terminal to be attached to the given socket. + * @param {Terminal} term - The terminal to be attached to the given socket. * @param {WebSocket} socket - The socket to attach the current terminal. * @param {boolean} bidirectional - Whether the terminal should send data * to the socket as well. @@ -82,7 +82,7 @@ /** * Detaches the given terminal from the given socket * - * @param {Xterm} term - The terminal to be detached from the given socket. + * @param {Terminal} term - The terminal to be detached from the given socket. * @param {WebSocket} socket - The socket from which to detach the current * terminal. */ @@ -108,7 +108,7 @@ * should happen instantly or at a maximum * frequency of 1 rendering per 10ms. */ - Xterm.prototype.attach = function (socket, bidirectional, buffered) { + Terminal.prototype.attach = function (socket, bidirectional, buffered) { return exports.attach(this, socket, bidirectional, buffered); }; @@ -118,7 +118,7 @@ * @param {WebSocket} socket - The socket from which to detach the current * terminal. */ - Xterm.prototype.detach = function (socket) { + Terminal.prototype.detach = function (socket) { return exports.detach(this, socket); }; diff --git a/src/addons/fit/fit.js b/src/addons/fit/fit.js index 46b79e9b..da66802d 100644 --- a/src/addons/fit/fit.js +++ b/src/addons/fit/fit.js @@ -16,7 +16,7 @@ /* * CommonJS environment */ - module.exports = fit(require('../../xterm')); + module.exports = fit(require('../../Terminal').Terminal); } else if (typeof define == 'function') { /* * Require.js is available @@ -28,7 +28,7 @@ */ fit(window.Terminal); } -})(function (Xterm) { +})(function (Terminal) { var exports = {}; exports.proposeGeometry = function (term) { @@ -74,11 +74,11 @@ } }; - Xterm.prototype.proposeGeometry = function () { + Terminal.prototype.proposeGeometry = function () { return exports.proposeGeometry(this); }; - Xterm.prototype.fit = function () { + Terminal.prototype.fit = function () { return exports.fit(this); }; diff --git a/src/addons/fullscreen/fullscreen.js b/src/addons/fullscreen/fullscreen.js index e8e34ea3..344669f6 100644 --- a/src/addons/fullscreen/fullscreen.js +++ b/src/addons/fullscreen/fullscreen.js @@ -8,7 +8,7 @@ /* * CommonJS environment */ - module.exports = fullscreen(require('../../xterm')); + module.exports = fullscreen(require('../../Terminal').Terminal); } else if (typeof define == 'function') { /* * Require.js is available @@ -20,12 +20,12 @@ */ fullscreen(window.Terminal); } -})(function (Xterm) { +})(function (Terminal) { var exports = {}; /** * Toggle the given terminal's fullscreen mode. - * @param {Xterm} 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) */ exports.toggleFullScreen = function (term, fullscreen) { @@ -42,7 +42,7 @@ term.element.classList[fn]('fullscreen'); }; - Xterm.prototype.toggleFullscreen = function (fullscreen) { + Terminal.prototype.toggleFullscreen = function (fullscreen) { exports.toggleFullScreen(this, fullscreen); }; diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 0b506b69..879ca4ee 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -20,7 +20,7 @@ declare var window: any; /** * CommonJS environment */ - module.exports = addon(require('../../xterm')); + module.exports = addon(require('../../Terminal').Terminal); } else if (typeof define === 'function') { /** * Require.js is available diff --git a/src/addons/terminado/terminado.js b/src/addons/terminado/terminado.js index 86e6ea2e..d1414c86 100644 --- a/src/addons/terminado/terminado.js +++ b/src/addons/terminado/terminado.js @@ -10,7 +10,7 @@ /* * CommonJS environment */ - module.exports = attach(require('../../xterm')); + module.exports = attach(require('../../Terminal').Terminal); } else if (typeof define == 'function') { /* * Require.js is available @@ -22,7 +22,7 @@ */ attach(window.Terminal); } -})(function (Xterm) { +})(function (Terminal) { 'use strict'; var exports = {}; @@ -30,7 +30,7 @@ /** * Attaches the given terminal to the given socket. * - * @param {Xterm} term - The terminal to be attached to the given socket. + * @param {Terminal} term - The terminal to be attached to the given socket. * @param {WebSocket} socket - The socket to attach the current terminal. * @param {boolean} bidirectional - Whether the terminal should send data * to the socket as well. @@ -117,7 +117,7 @@ * should happen instantly or at a maximum * frequency of 1 rendering per 10ms. */ - Xterm.prototype.terminadoAttach = function (socket, bidirectional, buffered) { + Terminal.prototype.terminadoAttach = function (socket, bidirectional, buffered) { return exports.terminadoAttach(this, socket, bidirectional, buffered); }; @@ -127,7 +127,7 @@ * @param {WebSocket} socket - The socket from which to detach the current * terminal. */ - Xterm.prototype.terminadoDetach = function (socket) { + Terminal.prototype.terminadoDetach = function (socket) { return exports.terminadoDetach(this, socket); }; diff --git a/src/handlers/Clipboard.test.ts b/src/handlers/Clipboard.test.ts index e5bc3581..bd2cea03 100644 --- a/src/handlers/Clipboard.test.ts +++ b/src/handlers/Clipboard.test.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import * as Terminal from '../xterm'; +import * as Terminal from '../Terminal'; import * as Clipboard from './Clipboard'; describe('evaluatePastedTextProcessing', () => { diff --git a/src/xterm.ts b/src/xterm.ts index 49e44151..50ac5592 100644 --- a/src/xterm.ts +++ b/src/xterm.ts @@ -1,18 +1,9 @@ /** * @license MIT + * + * This file is the entry point for browserify. */ import { Terminal } from './Terminal'; -/** - * Terminal Emulation References: - * http://vt100.net/ - * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt - * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html - * http://invisible-island.net/vttest/ - * http://www.inwap.com/pdp10/ansicode.txt - * http://linux.die.net/man/4/console_codes - * http://linux.die.net/man/7/urxvt - */ - module.exports = Terminal; From f21d5f25ecaa6c1c843ee6b2761c7958e1eb16ed Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 8 Aug 2017 00:29:22 -0700 Subject: [PATCH 3/3] Fix search addon after TS refactor Fixes #867 --- src/addons/search/SearchHelper.ts | 5 ++--- src/addons/search/search.ts | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 43d6dc18..26e4e8a7 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -15,7 +15,7 @@ interface ISearchResult { * A class that knows how to search the terminal and how to display the results. */ export class SearchHelper { - constructor(private _terminal: any, private _translateBufferLineToString: any) { + constructor(private _terminal: any) { // TODO: Search for multiple instances on 1 line // TODO: Don't use the actual selection, instead use a "find selection" so multiple instances can be highlighted // TODO: Highlight other instances in the viewport @@ -111,8 +111,7 @@ export class SearchHelper { * @return The search result if it was found. */ private _findInLine(term: string, y: number): ISearchResult { - const bufferLine = this._terminal.buffer.lines.get(y); - const lowerStringLine = this._translateBufferLineToString(bufferLine, true).toLowerCase(); + const lowerStringLine = this._terminal.buffer.translateBufferLineToString(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); const searchIndex = lowerStringLine.indexOf(lowerTerm); if (searchIndex >= 0) { diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 879ca4ee..34223c4e 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -36,7 +36,7 @@ declare var window: any; */ Terminal.prototype.findNext = function(term: string): boolean { if (!this._searchHelper) { - this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString); + this.searchHelper = new SearchHelper(this); } return (this.searchHelper).findNext(term); }; @@ -49,7 +49,7 @@ declare var window: any; */ Terminal.prototype.findPrevious = function(term: string): boolean { if (!this._searchHelper) { - this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString); + this.searchHelper = new SearchHelper(this); } return (this.searchHelper).findPrevious(term); };