mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
xterm: Provides its own types (#22869)
This commit is contained in:
@@ -1530,6 +1530,12 @@
|
||||
"sourceRepoURL": "github.com/node-xmpp/node-xmpp/",
|
||||
"asOfVersion": "1.2.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "xterm.js",
|
||||
"typingsPackageName": "xterm",
|
||||
"sourceRepoURL": "https://github.com/sourcelair/xterm.js/",
|
||||
"asOfVersion": "3.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "zetapush-js",
|
||||
"typingsPackageName": "zetapush-js",
|
||||
|
||||
96
types/xterm/index.d.ts
vendored
96
types/xterm/index.d.ts
vendored
@@ -1,96 +0,0 @@
|
||||
// Type definitions for xterm.js 2.0.1
|
||||
// Project: https://github.com/sourcelair/xterm.js/
|
||||
// Definitions by: Steven Silvester <https://github.com/blink1073>
|
||||
// Lucian Buzzo <https://github.com/LucianBuzzo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Typing for an xterm terminal object.
|
||||
*/
|
||||
interface Xterm {
|
||||
|
||||
cols: number;
|
||||
|
||||
rows: number;
|
||||
|
||||
options: Xterm.IOptions;
|
||||
|
||||
element: HTMLElement;
|
||||
|
||||
textarea: HTMLElement;
|
||||
|
||||
attachCustomKeydownHandler(callback: (event: KeyboardEvent) => boolean): void;
|
||||
|
||||
blur(): void;
|
||||
|
||||
clear(): void;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
focus(): void;
|
||||
|
||||
getOption(key: string): any;
|
||||
|
||||
on(event: string, callback: (...args: any[]) => void): void;
|
||||
|
||||
off(event: string, callback: (...args: any[]) => void): void;
|
||||
|
||||
open(parent: HTMLElement, focus?: boolean): void;
|
||||
|
||||
refresh(start: number, end: number, queue?: boolean): void;
|
||||
|
||||
reset(): void;
|
||||
|
||||
resize(x: number, y: number): void;
|
||||
|
||||
scrollDisp(n: number): void;
|
||||
|
||||
setOption(key: string, value: any): void;
|
||||
|
||||
write(text: string): void;
|
||||
|
||||
writeln(text: string): void;
|
||||
|
||||
fit?(): void;
|
||||
}
|
||||
|
||||
|
||||
interface XtermConstructor {
|
||||
new (options?: Xterm.IOptions): Xterm;
|
||||
(options?: Xterm.IOptions): Xterm;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A terminal options.
|
||||
*/
|
||||
declare namespace Xterm {
|
||||
interface IOptions {
|
||||
colors?: string[];
|
||||
|
||||
theme?: string;
|
||||
|
||||
convertEol?: boolean;
|
||||
|
||||
termName?: string;
|
||||
|
||||
geometry?: number[];
|
||||
|
||||
cursorBlink?: boolean;
|
||||
|
||||
visualBell?: boolean;
|
||||
|
||||
popOnBell?: boolean;
|
||||
|
||||
scrollback?: number;
|
||||
|
||||
debug?: boolean;
|
||||
|
||||
cancelEvents?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declare var Xterm: XtermConstructor;
|
||||
export = Xterm;
|
||||
export as namespace Xterm;
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"xterm-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
import * as Terminal from 'xterm';
|
||||
|
||||
declare var fetch: any;
|
||||
|
||||
var term: Terminal,
|
||||
protocol: any,
|
||||
socketURL: string,
|
||||
socket: WebSocket,
|
||||
pid: number,
|
||||
charWidth: number,
|
||||
charHeight: number;
|
||||
|
||||
var terminalContainer = document.getElementById('terminal-container'),
|
||||
optionElements = {
|
||||
cursorBlink: document.querySelector('#option-cursor-blink')
|
||||
},
|
||||
colsElement = document.getElementById('cols') as any,
|
||||
rowsElement = document.getElementById('rows') as any;
|
||||
|
||||
function setTerminalSize () {
|
||||
var cols = parseInt(colsElement.value),
|
||||
rows = parseInt(rowsElement.value),
|
||||
width = (cols * charWidth).toString() + 'px',
|
||||
height = (rows * charHeight).toString() + 'px';
|
||||
|
||||
terminalContainer.style.width = width;
|
||||
terminalContainer.style.height = height;
|
||||
term.resize(cols, rows);
|
||||
}
|
||||
|
||||
colsElement.addEventListener('change', setTerminalSize);
|
||||
rowsElement.addEventListener('change', setTerminalSize);
|
||||
|
||||
optionElements.cursorBlink.addEventListener('change', createTerminal);
|
||||
|
||||
createTerminal();
|
||||
|
||||
function createTerminal() {
|
||||
// Clean terminal
|
||||
while (terminalContainer.children.length) {
|
||||
terminalContainer.removeChild(terminalContainer.children[0]);
|
||||
}
|
||||
term = new Terminal({
|
||||
cursorBlink: (optionElements.cursorBlink as any).checked
|
||||
});
|
||||
term.on('resize', function (size: any) {
|
||||
if (!pid) {
|
||||
return;
|
||||
}
|
||||
var cols = size.cols,
|
||||
rows = size.rows,
|
||||
url = '/terminals/' + pid + '/size?cols=' + cols + '&rows=' + rows;
|
||||
|
||||
fetch(url, {method: 'POST'});
|
||||
});
|
||||
protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
|
||||
socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/';
|
||||
|
||||
term.open(terminalContainer);
|
||||
// term.fit();
|
||||
|
||||
var cols = 20,
|
||||
rows = 30;
|
||||
|
||||
colsElement.value = cols;
|
||||
rowsElement.value = rows;
|
||||
|
||||
fetch('/terminals?cols=' + cols + '&rows=' + rows, {method: 'POST'}).then(function (res: any) {
|
||||
|
||||
charWidth = Math.ceil(term.element.offsetWidth / cols);
|
||||
charHeight = Math.ceil(term.element.offsetHeight / rows);
|
||||
|
||||
res.text().then(function (pid: number) {
|
||||
(window as any).pid = pid;
|
||||
socketURL += pid;
|
||||
socket = new WebSocket(socketURL);
|
||||
socket.onopen = runRealTerminal;
|
||||
socket.onclose = runFakeTerminal;
|
||||
socket.onerror = runFakeTerminal;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function runRealTerminal() {
|
||||
//term.attach(socket);
|
||||
//term._initialized = true;
|
||||
}
|
||||
|
||||
function runFakeTerminal() {
|
||||
// if (term._initialized) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// term._initialized = true;
|
||||
|
||||
var shellprompt = '$ ';
|
||||
|
||||
// term.prompt = function () {
|
||||
// term.write('\r\n' + shellprompt);
|
||||
// };
|
||||
|
||||
term.writeln('Welcome to xterm.js');
|
||||
term.writeln('This is a local terminal emulation, without a real terminal in the back-end.');
|
||||
term.writeln('Type some keys and commands to play around.');
|
||||
term.writeln('');
|
||||
// term.prompt();
|
||||
|
||||
term.on('key', function (key, ev) {
|
||||
var printable = (
|
||||
!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey
|
||||
);
|
||||
|
||||
if (ev.keyCode == 13) {
|
||||
// term.prompt();
|
||||
} else if (ev.keyCode == 8) {
|
||||
// Do not delete the prompt
|
||||
// if (term.x > 2) {
|
||||
// term.write('\b \b');
|
||||
// }
|
||||
} else if (printable) {
|
||||
term.write(key);
|
||||
}
|
||||
});
|
||||
|
||||
term.on('paste', function (data, ev) {
|
||||
term.write(data);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user