mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Move terminal example over from Tyriar/vscode-terminal-api-example
Fixes Tyriar/vscode-terminal-api-example#4
This commit is contained in:
59
terminal-example/src/extension.ts
Normal file
59
terminal-example/src/extension.ts
Normal file
@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
let terminalStack = [];
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createTerminal', () => {
|
||||
terminalStack.push((<any>vscode.window).createTerminal(`Ext Terminal #${terminalStack.length + 1}`));
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.hide', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().hide();
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.show', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().show();
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.showPreserveFocus', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().show(true);
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendText', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().sendText("echo 'Hello world!'");
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendTextNoNewLine', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().sendText("echo 'Hello world!'", false);
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.dispose', () => {
|
||||
if (terminalStack.length === 0) {
|
||||
vscode.window.showErrorMessage('No active terminals');
|
||||
}
|
||||
getLatestTerminal().dispose();
|
||||
terminalStack.pop();
|
||||
}));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createAndSend', () => {
|
||||
terminalStack.push((<any>vscode.window).createTerminal(`Ext Terminal #${terminalStack.length + 1}`));
|
||||
getLatestTerminal().sendText("echo 'Sent text immediately after creating'");
|
||||
}));
|
||||
|
||||
function getLatestTerminal() {
|
||||
return terminalStack[terminalStack.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
}
|
||||
Reference in New Issue
Block a user