Move terminal example over from Tyriar/vscode-terminal-api-example

Fixes Tyriar/vscode-terminal-api-example#4
This commit is contained in:
Daniel Imms
2016-09-09 09:49:45 -07:00
parent b1ee9a11c5
commit 02b3918fa6
11 changed files with 221 additions and 0 deletions

2
terminal-example/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
out
node_modules

28
terminal-example/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,28 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"preLaunchTask": "npm"
}
]
}

10
terminal-example/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
}

30
terminal-example/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],
// The tsc compiler is started in watching mode
"isWatching": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}

View File

@ -0,0 +1,9 @@
.vscode/**
typings/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md

View File

@ -0,0 +1,13 @@
# vscode-terminal-api-example
This repo demonstrates how to utilize the integrated terminal extension API coming in Visual Studio Code v1.5.0.
Several commands are exposed prefixed with "Terminal API" that show how to use the API:
- `Terminal API: Create Terminal`: Create a terminal
- `Terminal API: Create Terminal and Immediately Send`: Create a terminal and immediately send text
- `Terminal API: Hide`: Hides the most recently created terminal
- `Terminal API: Show`: Shows the most recently created terminal
- `Terminal API: Send Text`: Sends `echo "Hello World!"` to the terminal
- `Terminal API: Send Text (no implied \n)`: Sends `echo "Hello World!"` to the terminal explicitly indicating to not add a `\n` to the end of the text
- `Terminal API: Dispose`: Disposes the most recently created terminal

View File

@ -0,0 +1,54 @@
{
"name": "vscode-terminal-api-example",
"displayName": "vscode-terminal-api-example",
"description": "abc",
"version": "0.0.1",
"publisher": "Tyriar",
"engines": {
"vscode": "^1.0.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:terminalTest.createTerminal",
"onCommand:terminalTest.createAndSend"
],
"main": "./out/src/extension",
"contributes": {
"commands": [{
"command": "terminalTest.createTerminal",
"title": "Terminal API: Create Terminal"
}, {
"command": "terminalTest.hide",
"title": "Terminal API: Hide"
}, {
"command": "terminalTest.show",
"title": "Terminal API: Show"
}, {
"command": "terminalTest.showPreserveFocus",
"title": "Terminal API: Show (preserving focus)"
}, {
"command": "terminalTest.sendText",
"title": "Terminal API: Send Text"
}, {
"command": "terminalTest.sendTextNoNewLine",
"title": "Terminal API: Send Text (no implied \\n)"
}, {
"command": "terminalTest.dispose",
"title": "Terminal API: Dispose"
}, {
"command": "terminalTest.createAndSend",
"title": "Terminal API: Create Terminal and Immediately Send"
}]
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.8.5",
"vscode": "^0.11.0"
}
}

View 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() {
}

View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "out",
"noLib": true,
"sourceMap": true,
"rootDir": "."
},
"exclude": [
"node_modules",
".vscode-test"
]
}

1
terminal-example/typings/node.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference path="../node_modules/vscode/typings/node.d.ts" />

View File

@ -0,0 +1 @@
/// <reference path="../node_modules/vscode/typings/index.d.ts" />