本文整理汇总了TypeScript中xterm.Terminal.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Terminal.on方法的具体用法?TypeScript Terminal.on怎么用?TypeScript Terminal.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xterm.Terminal
的用法示例。
在下文中一共展示了Terminal.on方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
public constructor(
private _rootProcessId: number,
private _rootShellExecutable: string,
private _terminalInstance: ITerminalInstance,
private _xterm: XTermTerminal
) {
if (!platform.isWindows) {
throw new Error(`WindowsShellHelper cannot be instantiated on ${platform.platform}`);
}
if (!windowsProcessTree) {
windowsProcessTree = require.__$__nodeRequire('windows-process-tree');
}
this._childProcessIdStack = [this._rootProcessId];
this._isDisposed = false;
this._onCheckShell = new Emitter<TPromise<string>>();
// The debounce is necessary to prevent multiple processes from spawning when
// the enter key or output is spammed
debounceEvent(this._onCheckShell.event, (l, e) => e, 150, true)(() => {
setTimeout(() => {
this.checkShell();
}, 50);
});
this._xterm.on('lineFeed', () => this._onCheckShell.fire());
this._xterm.on('keypress', () => this._onCheckShell.fire());
}
示例2: constructor
public constructor(
private _rootProcessId: number,
private _rootShellExecutable: string,
private _terminalInstance: ITerminalInstance,
private _xterm: XTermTerminal
) {
if (!platform.isWindows) {
throw new Error(`WindowsShellHelper cannot be instantiated on ${platform.platform}`);
}
if (!windowsProcessTree) {
windowsProcessTree = require.__$__nodeRequire('windows-process-tree');
}
this._childProcessIdStack = [this._rootProcessId];
this._isDisposed = false;
this._onCheckShell = new Emitter<TPromise<string>>();
// The debounce is necessary to prevent multiple processes from spawning when
// the enter key or output is spammed
debounceEvent(this._onCheckShell.event, (l, e) => e, 150, true)(() => {
setTimeout(() => {
this.checkShell();
}, 50);
});
// We want to fire a new check for the shell on a lineFeed, but only
// when parsing has finished which is indicated by the cursormove event.
// If this is done on every lineFeed, parsing ends up taking
// significantly longer due to resetting timers. Note that this is
// private API.
this._xterm.on('lineFeed', () => this._newLineFeed = true);
this._xterm.on('cursormove', () => {
if (this._newLineFeed) {
this._onCheckShell.fire();
}
});
// Fire a new check for the shell when any key is pressed.
this._xterm.on('keypress', () => this._onCheckShell.fire());
}
示例3: Terminal
{
const t: Terminal = new Terminal();
t.blur();
t.focus();
t.destroy();
t.clear();
t.refresh(0, 1);
t.reset();
t.resize(1, 1);
t.write('foo');
t.writeln('foo');
}
{
const t: Terminal = new Terminal();
// no arg
t.on('blur', () => {});
t.on('focus', () => {});
t.on('linefeed', () => {});
t.on('selection', () => {});
// args
t.on('data', () => {});
t.on('data', (data: string) => console.log(data));
t.on('key', () => {});
t.on('key', (key: string) => console.log(key, event));
t.on('key', (key: string, event: KeyboardEvent) => console.log(key, event));
t.on('keydown', () => {});
t.on('keydown', (event: KeyboardEvent) => console.log(event));
t.on('keypress', () => {});
t.on('keypress', (event: KeyboardEvent) => console.log(event));
t.on('refresh', () => {});
t.on('refresh', (data: {start: number, end: number}) => console.log(data));
示例4: Terminal
socket.on('connect', () => {
const term = new Terminal();
term.open(document.getElementById('terminal'));
const defaultOptions = { fontSize: 14 };
let options: any;
try {
if (localStorage.options === undefined) {
options = defaultOptions;
} else {
options = JSON.parse(localStorage.options);
}
} catch {
options = defaultOptions;
}
Object.keys(options).forEach(key => {
const value = options[key];
term.setOption(key, value);
});
const code = JSON.stringify(options, null, 2);
const editor = document.querySelector('#options .editor');
editor.value = code;
editor.addEventListener('keyup', e => {
try {
const updated = JSON.parse(editor.value);
const updatedCode = JSON.stringify(updated, null, 2);
editor.value = updatedCode;
editor.classList.remove('error');
localStorage.options = updatedCode;
Object.keys(updated).forEach(key => {
const value = updated[key];
term.setOption(key, value);
});
resize();
} catch {
// skip
editor.classList.add('error');
}
});
document.getElementById('overlay').style.display = 'none';
document.querySelector('#options .toggler').addEventListener('click', e => {
document.getElementById('options').classList.toggle('opened');
e.preventDefault();
});
window.addEventListener('beforeunload', handler, false);
/*
term.scrollPort_.screen_.setAttribute('contenteditable', 'false');
*/
term.attachCustomKeyEventHandler(e => {
// Ctrl + Shift + C
if (e.ctrlKey && e.shiftKey && e.keyCode === 67) {
e.preventDefault();
document.execCommand('copy');
return false;
}
return true;
});
function resize(): void {
fit(term);
socket.emit('resize', { cols: term.cols, rows: term.rows });
}
window.onresize = resize;
resize();
term.focus();
function kill(data: string): void {
disconnect(data);
}
term.on('data', data => {
socket.emit('input', data);
});
term.on('resize', size => {
socket.emit('resize', size);
});
socket
.on('data', (data: string) => {
term.write(data);
})
.on('login', () => {
term.writeln('');
resize();
})
.on('logout', kill)
.on('disconnect', kill)
.on('error', (err: string | null) => {
if (err) disconnect(err);
});
});