From 02b3918fa6ce5daf92edcfd6da9970e88a7343cd Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 9 Sep 2016 09:49:45 -0700 Subject: [PATCH] Move terminal example over from Tyriar/vscode-terminal-api-example Fixes Tyriar/vscode-terminal-api-example#4 --- terminal-example/.gitignore | 2 + terminal-example/.vscode/launch.json | 28 ++++++++++ terminal-example/.vscode/settings.json | 10 ++++ terminal-example/.vscode/tasks.json | 30 ++++++++++ terminal-example/.vscodeignore | 9 +++ terminal-example/README.md | 13 +++++ terminal-example/package.json | 54 ++++++++++++++++++ terminal-example/src/extension.ts | 59 ++++++++++++++++++++ terminal-example/tsconfig.json | 14 +++++ terminal-example/typings/node.d.ts | 1 + terminal-example/typings/vscode-typings.d.ts | 1 + 11 files changed, 221 insertions(+) create mode 100644 terminal-example/.gitignore create mode 100644 terminal-example/.vscode/launch.json create mode 100644 terminal-example/.vscode/settings.json create mode 100644 terminal-example/.vscode/tasks.json create mode 100644 terminal-example/.vscodeignore create mode 100644 terminal-example/README.md create mode 100644 terminal-example/package.json create mode 100644 terminal-example/src/extension.ts create mode 100644 terminal-example/tsconfig.json create mode 100644 terminal-example/typings/node.d.ts create mode 100644 terminal-example/typings/vscode-typings.d.ts diff --git a/terminal-example/.gitignore b/terminal-example/.gitignore new file mode 100644 index 00000000..8e5962ee --- /dev/null +++ b/terminal-example/.gitignore @@ -0,0 +1,2 @@ +out +node_modules \ No newline at end of file diff --git a/terminal-example/.vscode/launch.json b/terminal-example/.vscode/launch.json new file mode 100644 index 00000000..c77b2adf --- /dev/null +++ b/terminal-example/.vscode/launch.json @@ -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" + } + ] +} diff --git a/terminal-example/.vscode/settings.json b/terminal-example/.vscode/settings.json new file mode 100644 index 00000000..7877e3fc --- /dev/null +++ b/terminal-example/.vscode/settings.json @@ -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 +} \ No newline at end of file diff --git a/terminal-example/.vscode/tasks.json b/terminal-example/.vscode/tasks.json new file mode 100644 index 00000000..fb7f662e --- /dev/null +++ b/terminal-example/.vscode/tasks.json @@ -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" +} \ No newline at end of file diff --git a/terminal-example/.vscodeignore b/terminal-example/.vscodeignore new file mode 100644 index 00000000..93e28ff2 --- /dev/null +++ b/terminal-example/.vscodeignore @@ -0,0 +1,9 @@ +.vscode/** +typings/** +out/test/** +test/** +src/** +**/*.map +.gitignore +tsconfig.json +vsc-extension-quickstart.md diff --git a/terminal-example/README.md b/terminal-example/README.md new file mode 100644 index 00000000..1d325c17 --- /dev/null +++ b/terminal-example/README.md @@ -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 diff --git a/terminal-example/package.json b/terminal-example/package.json new file mode 100644 index 00000000..f81df6c4 --- /dev/null +++ b/terminal-example/package.json @@ -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" + } +} \ No newline at end of file diff --git a/terminal-example/src/extension.ts b/terminal-example/src/extension.ts new file mode 100644 index 00000000..feec1600 --- /dev/null +++ b/terminal-example/src/extension.ts @@ -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((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((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() { +} \ No newline at end of file diff --git a/terminal-example/tsconfig.json b/terminal-example/tsconfig.json new file mode 100644 index 00000000..eea16221 --- /dev/null +++ b/terminal-example/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "outDir": "out", + "noLib": true, + "sourceMap": true, + "rootDir": "." + }, + "exclude": [ + "node_modules", + ".vscode-test" + ] +} \ No newline at end of file diff --git a/terminal-example/typings/node.d.ts b/terminal-example/typings/node.d.ts new file mode 100644 index 00000000..5ed7730b --- /dev/null +++ b/terminal-example/typings/node.d.ts @@ -0,0 +1 @@ +/// \ No newline at end of file diff --git a/terminal-example/typings/vscode-typings.d.ts b/terminal-example/typings/vscode-typings.d.ts new file mode 100644 index 00000000..5590dc8c --- /dev/null +++ b/terminal-example/typings/vscode-typings.d.ts @@ -0,0 +1 @@ +///