terminal.ts 7.1 KB
Newer Older
D
Daniel Imms 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

7
import Event from 'vs/base/common/event';
8
import platform = require('vs/base/common/platform');
9
import processes = require('vs/base/node/processes');
10 11 12
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
D
Daniel Imms 已提交
13 14 15 16 17

export const TERMINAL_PANEL_ID = 'workbench.panel.terminal';

export const TERMINAL_SERVICE_ID = 'terminalService';

18 19
export const TERMINAL_DEFAULT_SHELL_LINUX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
export const TERMINAL_DEFAULT_SHELL_OSX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
20
export const TERMINAL_DEFAULT_SHELL_WINDOWS = processes.getWindowsShell();
21

22
/**  A context key that is set when the integrated terminal has focus. */
A
Alex Dima 已提交
23
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new RawContextKey<boolean>('terminalFocus', undefined);
24
/**  A context key that is set when the integrated terminal does not have focus. */
J
Johannes Rieken 已提交
25
export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated();
26

27 28 29 30 31
/** A keybinding context key that is set when the integrated terminal has text selected. */
export const KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED = new RawContextKey<boolean>('terminalTextSelected', undefined);
/** A keybinding context key that is set when the integrated terminal does not have text selected. */
export const KEYBINDING_CONTEXT_TERMINAL_TEXT_NOT_SELECTED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED.toNegated();

B
Benjamin Pasero 已提交
32
export const ITerminalService = createDecorator<ITerminalService>(TERMINAL_SERVICE_ID);
D
Daniel Imms 已提交
33

34
export interface ITerminalConfiguration {
35 36 37 38 39 40 41
	terminal: {
		integrated: {
			shell: {
				linux: string,
				osx: string,
				windows: string
			},
D
Daniel Imms 已提交
42 43
			shellArgs: {
				linux: string[],
44 45
				osx: string[],
				windows: string[]
D
Daniel Imms 已提交
46
			},
47
			cursorBlinking: boolean,
48
			fontFamily: string,
49
			fontLigatures: boolean,
50
			fontSize: number,
51
			lineHeight: number,
52
			setLocaleVariables: boolean,
D
Daniel Imms 已提交
53
			scrollback: number,
54
			commandsToSkipShell: string[]
55
		}
56 57 58
	};
}

59 60 61 62 63 64
export interface ITerminalConfigHelper {
	getTheme(baseThemeId: string): string[];
	getFont(): ITerminalFont;
	getFontLigaturesEnabled(): boolean;
	getCursorBlink(): boolean;
	getCommandsToSkipShell(): string[];
D
Daniel Imms 已提交
65
	getScrollback(): number;
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
}

export interface ITerminalFont {
	fontFamily: string;
	fontSize: string;
	lineHeight: number;
	charWidth: number;
	charHeight: number;
}

export interface IShell {
	executable: string;
	args: string[];
}

D
Daniel Imms 已提交
81
export interface ITerminalService {
82
	_serviceBrand: any;
83

D
Daniel Imms 已提交
84
	activeTerminalInstanceIndex: number;
85
	configHelper: ITerminalConfigHelper;
86
	onActiveInstanceChanged: Event<string>;
87
	onInstanceDisposed: Event<ITerminalInstance>;
88
	onInstanceProcessIdReady: Event<ITerminalInstance>;
89 90
	onInstancesChanged: Event<string>;
	onInstanceTitleChanged: Event<string>;
91 92
	terminalInstances: ITerminalInstance[];

P
Pine Wu 已提交
93
	createInstance(name?: string, shellPath?: string, shellArgs?: string[]): ITerminalInstance;
94
	getInstanceFromId(terminalId: number): ITerminalInstance;
D
Daniel Imms 已提交
95
	getInstanceLabels(): string[];
96 97 98 99 100 101 102
	getActiveInstance(): ITerminalInstance;
	setActiveInstance(terminalInstance: ITerminalInstance): void;
	setActiveInstanceByIndex(terminalIndex: number): void;
	setActiveInstanceToNext(): void;
	setActiveInstanceToPrevious(): void;

	showPanel(focus?: boolean): TPromise<void>;
D
Daniel Imms 已提交
103
	hidePanel(): void;
104
	setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void;
105
	updateConfig(): void;
D
Daniel Imms 已提交
106
}
D
Daniel Imms 已提交
107

108
export interface ITerminalInstance {
D
jsdoc  
Daniel Imms 已提交
109 110 111 112
	/**
	 * The ID of the terminal instance, this is an arbitrary number only used to identify the
	 * terminal instance.
	 */
113
	id: number;
D
jsdoc  
Daniel Imms 已提交
114

115 116 117 118 119
	/**
	 * The process ID of the shell process.
	 */
	processId: number;

D
jsdoc  
Daniel Imms 已提交
120 121 122
	/**
	 * An event that fires when the terminal instance's title changes.
	 */
D
Daniel Imms 已提交
123
	onTitleChanged: Event<string>;
D
jsdoc  
Daniel Imms 已提交
124 125 126 127 128 129 130

	/**
	 * The title of the terminal. This is either title or the process currently running or an
	 * explicit name given to the terminal instance through the extension API.
	 *
	 * @readonly
	 */
131 132
	title: string;

K
Kai Wood 已提交
133 134 135 136 137 138 139
	/**
	 * The focus state of the terminal before exiting.
	 *
	 * @readonly
	 */
	hadFocusOnExit: boolean;

D
jsdoc  
Daniel Imms 已提交
140 141 142
	/**
	 * Dispose the terminal instance, removing it from the panel/service and freeing up resources.
	 */
143
	dispose(): void;
D
jsdoc  
Daniel Imms 已提交
144 145 146 147

	/**
	 * Copies the terminal selection to the clipboard.
	 */
148
	copySelection(): void;
D
jsdoc  
Daniel Imms 已提交
149 150 151 152 153 154

	/**
	 * Focuses the terminal instance.
	 *
	 * @param focus Force focus even if there is a selection.
	 */
D
Daniel Imms 已提交
155
	focus(force?: boolean): void;
D
jsdoc  
Daniel Imms 已提交
156 157 158 159

	/**
	 * Focuses and pastes the contents of the clipboard into the terminal instance.
	 */
160
	paste(): void;
D
jsdoc  
Daniel Imms 已提交
161 162 163 164 165 166 167 168 169 170

	/**
	 * Send text to the terminal instance. The text is written to the stdin of the underlying pty
	 * process (shell) of the terminal instance.
	 *
	 * @param text The text to send.
	 * @param addNewLine Whether to add a new line to the text being sent, this is normally
	 * required to run a command in the terminal. The character(s) added are \n or \r\n
	 * depending on the platform. This defaults to `true`.
	 */
171
	sendText(text: string, addNewLine: boolean): void;
D
jsdoc  
Daniel Imms 已提交
172

173 174 175 176
	/** Scroll the terminal buffer down 1 line. */
	scrollDownLine(): void;
	/** Scroll the terminal buffer down 1 page. */
	scrollDownPage(): void;
177 178
	/** Scroll the terminal buffer to the bottom. */
	scrollToBottom(): void;
179 180 181 182
	/** Scroll the terminal buffer up 1 line. */
	scrollUpLine(): void;
	/** Scroll the terminal buffer up 1 page. */
	scrollUpPage(): void;
183 184
	/** Scroll the terminal buffer to the top. */
	scrollToTop(): void;
D
Daniel Imms 已提交
185

D
Daniel Imms 已提交
186 187 188 189 190
	/**
	 * Clears the terminal buffer, leaving only the prompt line.
	 */
	clear(): void;

D
jsdoc  
Daniel Imms 已提交
191 192 193 194 195 196
	/**
	 * Attaches the terminal instance to an element on the DOM, before this is called the terminal
	 * instance process may run in the background but cannot be displayed on the UI.
	 *
	 * @param container The element to attach the terminal instance to.
	 */
D
Daniel Imms 已提交
197
	attachToElement(container: HTMLElement): void;
D
jsdoc  
Daniel Imms 已提交
198 199 200 201 202 203

	/**
	 * Sets whether the terminal instance's cursor will blink or be solid.
	 *
	 * @param blink Whether the cursor will blink.
	 */
D
Daniel Imms 已提交
204
	setCursorBlink(blink: boolean): void;
D
jsdoc  
Daniel Imms 已提交
205 206 207 208 209

	/**
	 * Sets the array of commands that skip the shell process so they can be handled by VS Code's
	 * keybinding system.
	 */
D
Daniel Imms 已提交
210
	setCommandsToSkipShell(commands: string[]): void;
D
jsdoc  
Daniel Imms 已提交
211

D
Daniel Imms 已提交
212 213 214 215 216
	/**
	 * Sets the maximum amount of lines that the buffer can store before discarding old ones.
	 */
	setScrollback(lineCount: number): void;

D
jsdoc  
Daniel Imms 已提交
217 218 219 220 221
	/**
	 * Configure the dimensions of the terminal instance.
	 *
	 * @param dimension The dimensions of the container.
	 */
222
	layout(dimension: { width: number, height: number }): void;
D
jsdoc  
Daniel Imms 已提交
223 224 225 226 227 228

	/**
	 * Sets whether the terminal instance's element is visible in the DOM.
	 *
	 * @param visible Whether the element is visible.
	 */
D
Daniel Imms 已提交
229
	setVisible(visible: boolean): void;
D
Daniel Imms 已提交
230
}