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 48 49 50 51
			rightClickAction: {
				linux: string,
				osx: string,
				windows: string
			},
52
			cursorBlinking: boolean,
53
			fontFamily: string,
54
			fontLigatures: boolean,
55
			fontSize: number,
56
			lineHeight: number,
57
			setLocaleVariables: boolean,
D
Daniel Imms 已提交
58
			scrollback: number,
59
			commandsToSkipShell: string[],
D
Daniel Imms 已提交
60
			cwd: string
61
		}
62 63 64
	};
}

65 66 67 68 69
export interface ITerminalConfigHelper {
	getTheme(baseThemeId: string): string[];
	getFont(): ITerminalFont;
	getFontLigaturesEnabled(): boolean;
	getCursorBlink(): boolean;
70
	getRightClickAction(): string;
71
	getCommandsToSkipShell(): string[];
D
Daniel Imms 已提交
72
	getScrollback(): number;
D
Daniel Imms 已提交
73
	getCwd(): string;
74 75 76 77 78 79 80 81 82 83 84 85 86
}

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

export interface IShell {
	executable: string;
	args: string[];
D
Daniel Imms 已提交
87 88
	/** Whether to ignore a custom cwd (if the shell is being launched by an extension) */
	ignoreCustomCwd?: boolean;
89 90
}

D
Daniel Imms 已提交
91
export interface ITerminalService {
92
	_serviceBrand: any;
93

D
Daniel Imms 已提交
94
	activeTerminalInstanceIndex: number;
95
	configHelper: ITerminalConfigHelper;
96
	onActiveInstanceChanged: Event<string>;
97
	onInstanceDisposed: Event<ITerminalInstance>;
98
	onInstanceProcessIdReady: Event<ITerminalInstance>;
99 100
	onInstancesChanged: Event<string>;
	onInstanceTitleChanged: Event<string>;
101 102
	terminalInstances: ITerminalInstance[];

D
Daniel Imms 已提交
103
	createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomCwd?: boolean): ITerminalInstance;
104
	getInstanceFromId(terminalId: number): ITerminalInstance;
D
Daniel Imms 已提交
105
	getInstanceLabels(): string[];
106 107 108 109 110 111 112
	getActiveInstance(): ITerminalInstance;
	setActiveInstance(terminalInstance: ITerminalInstance): void;
	setActiveInstanceByIndex(terminalIndex: number): void;
	setActiveInstanceToNext(): void;
	setActiveInstanceToPrevious(): void;

	showPanel(focus?: boolean): TPromise<void>;
D
Daniel Imms 已提交
113
	hidePanel(): void;
114
	setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void;
115
	updateConfig(): void;
D
Daniel Imms 已提交
116
}
D
Daniel Imms 已提交
117

118
export interface ITerminalInstance {
D
jsdoc  
Daniel Imms 已提交
119 120 121 122
	/**
	 * The ID of the terminal instance, this is an arbitrary number only used to identify the
	 * terminal instance.
	 */
123
	id: number;
D
jsdoc  
Daniel Imms 已提交
124

125 126 127 128 129
	/**
	 * The process ID of the shell process.
	 */
	processId: number;

D
jsdoc  
Daniel Imms 已提交
130 131 132
	/**
	 * An event that fires when the terminal instance's title changes.
	 */
D
Daniel Imms 已提交
133
	onTitleChanged: Event<string>;
D
jsdoc  
Daniel Imms 已提交
134 135 136 137 138 139 140

	/**
	 * 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
	 */
141 142
	title: string;

K
Kai Wood 已提交
143 144 145 146 147 148 149
	/**
	 * The focus state of the terminal before exiting.
	 *
	 * @readonly
	 */
	hadFocusOnExit: boolean;

D
jsdoc  
Daniel Imms 已提交
150 151 152
	/**
	 * Dispose the terminal instance, removing it from the panel/service and freeing up resources.
	 */
153
	dispose(): void;
D
jsdoc  
Daniel Imms 已提交
154

155 156 157 158 159
	/**
	 * Check if anything is selected in terminal.
	 */
	hasSelection(): boolean;

D
jsdoc  
Daniel Imms 已提交
160 161 162
	/**
	 * Copies the terminal selection to the clipboard.
	 */
163
	copySelection(): void;
D
jsdoc  
Daniel Imms 已提交
164

165 166 167 168 169
	/**
	 * Clear current selection.
	 */
	clearSelection(): void;

D
jsdoc  
Daniel Imms 已提交
170 171 172 173 174
	/**
	 * Focuses the terminal instance.
	 *
	 * @param focus Force focus even if there is a selection.
	 */
D
Daniel Imms 已提交
175
	focus(force?: boolean): void;
D
jsdoc  
Daniel Imms 已提交
176 177 178 179

	/**
	 * Focuses and pastes the contents of the clipboard into the terminal instance.
	 */
180
	paste(): void;
D
jsdoc  
Daniel Imms 已提交
181 182 183 184 185 186 187 188 189 190

	/**
	 * 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`.
	 */
191
	sendText(text: string, addNewLine: boolean): void;
D
jsdoc  
Daniel Imms 已提交
192

193 194 195 196
	/** Scroll the terminal buffer down 1 line. */
	scrollDownLine(): void;
	/** Scroll the terminal buffer down 1 page. */
	scrollDownPage(): void;
197 198
	/** Scroll the terminal buffer to the bottom. */
	scrollToBottom(): void;
199 200 201 202
	/** Scroll the terminal buffer up 1 line. */
	scrollUpLine(): void;
	/** Scroll the terminal buffer up 1 page. */
	scrollUpPage(): void;
203 204
	/** Scroll the terminal buffer to the top. */
	scrollToTop(): void;
D
Daniel Imms 已提交
205

D
Daniel Imms 已提交
206 207 208 209 210
	/**
	 * Clears the terminal buffer, leaving only the prompt line.
	 */
	clear(): void;

D
jsdoc  
Daniel Imms 已提交
211 212 213 214 215 216
	/**
	 * 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 已提交
217
	attachToElement(container: HTMLElement): void;
D
jsdoc  
Daniel Imms 已提交
218 219

	/**
220
	 * Updates the configuration of the terminal instance.
D
jsdoc  
Daniel Imms 已提交
221
	 */
222
	updateConfig(): void;
D
Daniel Imms 已提交
223

D
jsdoc  
Daniel Imms 已提交
224 225 226 227 228
	/**
	 * Configure the dimensions of the terminal instance.
	 *
	 * @param dimension The dimensions of the container.
	 */
229
	layout(dimension: { width: number, height: number }): void;
D
jsdoc  
Daniel Imms 已提交
230 231 232 233 234 235

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