Skip to content

Commit

Permalink
Merge pull request #868 from Tyriar/865_fix_module_build
Browse files Browse the repository at this point in the history
Fix module build, add TS declaration files, fix search addon
  • Loading branch information
Tyriar authored Aug 8, 2017
2 parents 17c3ec0 + f21d5f2 commit 91bf319
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 48 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions src/addons/attach/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,15 +21,15 @@
*/
attach(window.Terminal);
}
})(function (Xterm) {
})(function (Terminal) {
'use strict';

var exports = {};

/**
* 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.
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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);
};

Expand All @@ -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);
};

Expand Down
8 changes: 4 additions & 4 deletions src/addons/fit/fit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +28,7 @@
*/
fit(window.Terminal);
}
})(function (Xterm) {
})(function (Terminal) {
var exports = {};

exports.proposeGeometry = function (term) {
Expand Down Expand Up @@ -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);
};

Expand Down
8 changes: 4 additions & 4 deletions src/addons/fullscreen/fullscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -42,7 +42,7 @@
term.element.classList[fn]('fullscreen');
};

Xterm.prototype.toggleFullscreen = function (fullscreen) {
Terminal.prototype.toggleFullscreen = function (fullscreen) {
exports.toggleFullScreen(this, fullscreen);
};

Expand Down
5 changes: 2 additions & 3 deletions src/addons/search/SearchHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/addons/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (<SearchHelper>this.searchHelper).findNext(term);
};
Expand All @@ -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 (<SearchHelper>this.searchHelper).findPrevious(term);
};
Expand Down
10 changes: 5 additions & 5 deletions src/addons/terminado/terminado.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,15 +22,15 @@
*/
attach(window.Terminal);
}
})(function (Xterm) {
})(function (Terminal) {
'use strict';

var exports = {};

/**
* 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.
Expand Down Expand Up @@ -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);
};

Expand All @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/Clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
13 changes: 2 additions & 11 deletions src/xterm.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"module": "commonjs",
"target": "es5",
"rootDir": "src",
"allowJs": true,
"outDir": "lib",
"sourceMap": true,
"removeComments": true
"removeComments": true,
"declaration": true
},
"include": [
"src/**/*"
Expand Down
6 changes: 0 additions & 6 deletions typings.json

This file was deleted.

0 comments on commit 91bf319

Please sign in to comment.