-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2164 from Tyriar/addons_in_repo
Move new format addons into repo, remove old addons
- Loading branch information
Showing
72 changed files
with
887 additions
and
1,621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ fixtures/ | |
demo/ | ||
.devcontainer/ | ||
out/ | ||
addons/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/*.api.js | ||
**/*.api.ts | ||
tsconfig.json | ||
.yarnrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2017, The xterm.js authors (https://github.com/xtermjs/xterm.js) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@xtermjs/addon-attach", | ||
"version": "0.1.0-beta8", | ||
"author": { | ||
"name": "The xterm.js authors", | ||
"url": "https://xtermjs.org/" | ||
}, | ||
"main": "lib/AttachAddon.js", | ||
"types": "typings/attach.d.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"prepublishOnly": "../../../node_modules/.bin/tsc -p src" | ||
}, | ||
"peerDependencies": { | ||
"xterm": "^3.14.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import * as puppeteer from 'puppeteer'; | ||
import { assert } from 'chai'; | ||
import { ITerminalOptions } from 'xterm'; | ||
import WebSocket = require('ws'); | ||
|
||
const APP = 'http://127.0.0.1:3000/test'; | ||
|
||
let browser: puppeteer.Browser; | ||
let page: puppeteer.Page; | ||
const width = 800; | ||
const height = 600; | ||
|
||
describe('AttachAddon', () => { | ||
before(async function(): Promise<any> { | ||
this.timeout(10000); | ||
browser = await puppeteer.launch({ | ||
headless: process.argv.indexOf('--headless') !== -1, | ||
slowMo: 80, | ||
args: [`--window-size=${width},${height}`] | ||
}); | ||
page = (await browser.pages())[0]; | ||
await page.setViewport({ width, height }); | ||
}); | ||
|
||
after(async () => { | ||
await browser.close(); | ||
}); | ||
|
||
beforeEach(async function(): Promise<any> { | ||
this.timeout(5000); | ||
await page.goto(APP); | ||
}); | ||
|
||
it('string', async function(): Promise<any> { | ||
this.timeout(20000); | ||
await openTerminal({ rendererType: 'dom' }); | ||
const port = 8080; | ||
const server = new WebSocket.Server({ port }); | ||
server.on('connection', socket => socket.send('foo')); | ||
await page.evaluate(`window.term.loadAddon(new window.AttachAddon(new WebSocket('ws://localhost:${port}')))`); | ||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'foo'); | ||
server.close(); | ||
}); | ||
|
||
it('utf8', async function(): Promise<any> { | ||
this.timeout(20000); | ||
await openTerminal({ rendererType: 'dom' }); | ||
const port = 8080; | ||
const server = new WebSocket.Server({ port }); | ||
const data = new Uint8Array([102, 111, 111]); | ||
server.on('connection', socket => socket.send(data)); | ||
await page.evaluate(`window.term.loadAddon(new window.AttachAddon(new WebSocket('ws://localhost:${port}'), { inputUtf8: true }))`); | ||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), 'foo'); | ||
server.close(); | ||
}); | ||
}); | ||
|
||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> { | ||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`); | ||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`); | ||
if (options.rendererType === 'dom') { | ||
await page.waitForSelector('.xterm-rows'); | ||
} else { | ||
await page.waitForSelector('.xterm-text-layer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) 2014, 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
* | ||
* Implements the attach method, that attaches the terminal to a WebSocket stream. | ||
*/ | ||
|
||
import { Terminal, IDisposable, ITerminalAddon } from 'xterm'; | ||
|
||
interface IAttachOptions { | ||
bidirectional?: boolean; | ||
inputUtf8?: boolean; | ||
} | ||
|
||
export class AttachAddon implements ITerminalAddon { | ||
private _socket: WebSocket; | ||
private _bidirectional: boolean; | ||
private _utf8: boolean; | ||
private _disposables: IDisposable[] = []; | ||
|
||
constructor(socket: WebSocket, options?: IAttachOptions) { | ||
this._socket = socket; | ||
// always set binary type to arraybuffer, we do not handle blobs | ||
this._socket.binaryType = 'arraybuffer'; | ||
this._bidirectional = (options && options.bidirectional === false) ? false : true; | ||
this._utf8 = !!(options && options.inputUtf8); | ||
} | ||
|
||
public activate(terminal: Terminal): void { | ||
if (this._utf8) { | ||
this._disposables.push(addSocketListener(this._socket, 'message', | ||
(ev: MessageEvent | Event | CloseEvent) => terminal.writeUtf8(new Uint8Array((ev as any).data as ArrayBuffer)))); | ||
} else { | ||
this._disposables.push(addSocketListener(this._socket, 'message', | ||
(ev: MessageEvent | Event | CloseEvent) => terminal.write((ev as any).data as string))); | ||
} | ||
|
||
if (this._bidirectional) { | ||
this._disposables.push(terminal.onData(data => this._sendData(data))); | ||
} | ||
|
||
this._disposables.push(addSocketListener(this._socket, 'close', () => this.dispose())); | ||
this._disposables.push(addSocketListener(this._socket, 'error', () => this.dispose())); | ||
} | ||
|
||
public dispose(): void { | ||
this._disposables.forEach(d => d.dispose()); | ||
} | ||
|
||
private _sendData(data: string): void { | ||
// TODO: do something better than just swallowing | ||
// the data if the socket is not in a working condition | ||
if (this._socket.readyState !== 1) { | ||
return; | ||
} | ||
this._socket.send(data); | ||
} | ||
} | ||
|
||
function addSocketListener(socket: WebSocket, type: string, handler: (this: WebSocket, ev: MessageEvent | Event | CloseEvent) => any): IDisposable { | ||
socket.addEventListener(type, handler); | ||
return { | ||
dispose: () => { | ||
if (!handler) { | ||
// Already disposed | ||
return; | ||
} | ||
socket.removeEventListener(type, handler); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2015", | ||
"lib": [ | ||
"dom", | ||
"es2015" | ||
], | ||
"rootDir": ".", | ||
"outDir": "../lib", | ||
"sourceMap": true, | ||
"removeComments": true, | ||
"strict": true | ||
}, | ||
"include": [ | ||
"./**/*", | ||
"../../../../typings/xterm.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2017 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { Terminal, ILinkMatcherOptions, ITerminalAddon } from 'xterm'; | ||
|
||
declare module '@xtermjs/addon-attach' { | ||
export interface IAttachOptions { | ||
/** | ||
* Whether input should be written to the backend. Defaults to `true`. | ||
*/ | ||
bidirectional?: boolean; | ||
|
||
/** | ||
* Whether to use UTF8 binary transport for incoming messages. Defaults to `false`. | ||
* Note: This must be in line with the server side of the websocket. | ||
* Always send string messages from the backend if this options is false, | ||
* otherwise always binary UTF8 data. | ||
*/ | ||
inputUtf8?: boolean; | ||
} | ||
|
||
export class AttachAddon implements ITerminalAddon { | ||
constructor(socket: WebSocket, options?: IAttachOptions); | ||
public activate(terminal: Terminal): void; | ||
public dispose(): void; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/*.api.js | ||
**/*.api.ts | ||
tsconfig.json | ||
.yarnrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2019, The xterm.js authors (https://github.com/xtermjs/xterm.js) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@xtermjs/addon-fit", | ||
"version": "0.1.0-beta7", | ||
"author": { | ||
"name": "The xterm.js authors", | ||
"url": "https://xtermjs.org/" | ||
}, | ||
"main": "lib/FitAddon.js", | ||
"types": "typings/fit.d.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"prepublishOnly": "../../../node_modules/.bin/tsc -p src" | ||
}, | ||
"peerDependencies": { | ||
"xterm": "^3.14.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (c) 2017 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { Terminal, ITerminalAddon } from 'xterm'; | ||
|
||
interface ITerminalDimensions { | ||
/** | ||
* The number of rows in the terminal. | ||
*/ | ||
rows: number; | ||
|
||
/** | ||
* The number of columns in the terminal. | ||
*/ | ||
cols: number; | ||
} | ||
|
||
export class FitAddon implements ITerminalAddon { | ||
private _terminal: Terminal | undefined; | ||
|
||
constructor() {} | ||
|
||
public activate(terminal: Terminal): void { | ||
this._terminal = terminal; | ||
} | ||
|
||
public dispose(): void {} | ||
|
||
public fit(): void { | ||
const dims = this.proposeDimensions(); | ||
if (!dims || !this._terminal) { | ||
return; | ||
} | ||
|
||
// TODO: Remove reliance on private API | ||
const core = (<any>this._terminal)._core; | ||
|
||
// Force a full render | ||
if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) { | ||
core._renderCoordinator.clear(); | ||
this._terminal.resize(dims.cols, dims.rows); | ||
} | ||
} | ||
|
||
public proposeDimensions(): ITerminalDimensions | undefined { | ||
if (!this._terminal) { | ||
return undefined; | ||
} | ||
|
||
if (!this._terminal.element.parentElement) { | ||
return undefined; | ||
} | ||
|
||
// TODO: Remove reliance on private API | ||
const core = (<any>this._terminal)._core; | ||
|
||
const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement); | ||
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')); | ||
const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width'))); | ||
const elementStyle = window.getComputedStyle(this._terminal.element); | ||
const elementPadding = { | ||
top: parseInt(elementStyle.getPropertyValue('padding-top')), | ||
bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')), | ||
right: parseInt(elementStyle.getPropertyValue('padding-right')), | ||
left: parseInt(elementStyle.getPropertyValue('padding-left')) | ||
}; | ||
const elementPaddingVer = elementPadding.top + elementPadding.bottom; | ||
const elementPaddingHor = elementPadding.right + elementPadding.left; | ||
const availableHeight = parentElementHeight - elementPaddingVer; | ||
const availableWidth = parentElementWidth - elementPaddingHor - core.viewport.scrollBarWidth; | ||
const geometry = { | ||
cols: Math.floor(availableWidth / core._renderCoordinator.dimensions.actualCellWidth), | ||
rows: Math.floor(availableHeight / core._renderCoordinator.dimensions.actualCellHeight) | ||
}; | ||
return geometry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.