Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #41 from eclipse/updateTerminalToTheLatestApi
Browse files Browse the repository at this point in the history
Update terminal extension to the theia 0.3.19
  • Loading branch information
AndrienkoAleksandr authored Jan 29, 2019
2 parents 9cfdfaf + 7a7bfca commit 348956e
Show file tree
Hide file tree
Showing 9 changed files with 954 additions and 531 deletions.
4 changes: 2 additions & 2 deletions extensions/eclipse-che-theia-plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"dependencies": {
"@eclipse-che/plugin": "latest",
"@eclipse-che/workspace-client": "^0.0.1-1546509769",
"@theia/core": "0.3.18",
"@theia/plugin-ext": "0.3.18"
"@theia/core": "0.3.19",
"@theia/plugin-ext": "0.3.19"
},
"devDependencies": {
"clean-webpack-plugin": "^0.1.19",
Expand Down
739 changes: 350 additions & 389 deletions extensions/eclipse-che-theia-plugin-ext/yarn.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions extensions/eclipse-che-theia-plugin/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@


"@eclipse-che/api@^6.16.1":
version "6.16.1"
resolved "https://registry.yarnpkg.com/@eclipse-che/api/-/api-6.16.1.tgz#5b5e70285cf27d525df3752c938388e36f7925d6"
version "6.17.1"
resolved "https://registry.yarnpkg.com/@eclipse-che/api/-/api-6.17.1.tgz#bae00a5ac60501566759ff07b134867996ce8964"
integrity sha512-kXrUsNJWUkoZfw9wOKgtZH8KYntjXqkyIHNduXMyELFizpV8n94PWBvSj6MeyeKqogKO5QmeC5xvFZS5/I1fkg==

"@types/node@^10.11.7":
version "10.12.18"
Expand Down
6 changes: 3 additions & 3 deletions extensions/eclipse-che-theia-terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"src"
],
"dependencies": {
"@theia/core": "0.3.17",
"@theia/terminal": "0.3.17",
"@theia/core": "0.3.19",
"@theia/terminal": "0.3.19",
"xterm": "3.9.1",
"@eclipse-che/workspace-client": "latest",
"@eclipse-che/api": "latest"
},
"license": "EPL-2.0",
"devDependencies": {
"typescript": "2.9.2",
"typescript": "3.1.3",
"rimraf": "2.6.2"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ import { BrowserMainMenuFactory } from '@theia/core/lib/browser/menu/browser-men
import { MenuBar as MenuBarWidget } from '@phosphor/widgets';
import { TerminalKeybindingContext } from './keybinding-context';
import { CHEWorkspaceService } from '../../common/workspace-service';
import { TerminalWidget, TerminalWidgetOptions } from '@theia/terminal/lib/browser/base/terminal-widget';
import { REMOTE_TERMINAL_WIDGET_FACTORY_ID } from '../terminal-widget/remote-terminal-widget';

export const NewTerminalInSpecificContainer = {
id: 'terminal-in-specific-container:new',
label: 'Open Terminal in specific container'
};

export interface OpenTerminalHandler {
(containerName: string)
}

@injectable()
export class ExecTerminalFrontendContribution extends TerminalFrontendContribution {

Expand All @@ -50,7 +56,9 @@ export class ExecTerminalFrontendContribution extends TerminalFrontendContributi
if (serverUrl) {
registry.registerCommand(NewTerminalInSpecificContainer, {
execute: () => {
this.terminalQuickOpen.displayListMachines();
this.terminalQuickOpen.displayListMachines((containerName) => {
this.openTerminalByContainerName(containerName);
});
}
});
await this.registerTerminalCommandPerContainer(registry);
Expand All @@ -66,19 +74,44 @@ export class ExecTerminalFrontendContribution extends TerminalFrontendContributi
if (containers.hasOwnProperty(containerName)) {
const termCommandPerContainer: Command = {
id: "terminal-for-" + containerName + "-container:new",
label: "New terminal for " + containerName // todo Final solution about command labels
label: "New terminal for " + containerName
};
registry.registerCommand(termCommandPerContainer, {
execute: async () => {
const termWidget = await this.terminalQuickOpen.newTerminalPerContainer(containerName);
this.terminalQuickOpen.activateTerminal(termWidget);
termWidget.start();
}
execute: async () => this.openTerminalByContainerName(containerName)
});
}
}
}

async openTerminalByContainerName(containerName: string): Promise<void> {
const termWidget = await this.terminalQuickOpen.newTerminalPerContainer(containerName, {});
this.open(termWidget, {});
termWidget.start();
}

async newTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
let containerName;

if (options.attributes) {
containerName = options.attributes['CHE_MACHINE_NAME'];
}

if (!containerName) {
containerName = await this.cheWorkspaceService.findEditorMachineName();
}

if (containerName) {
const termWidget = await this.terminalQuickOpen.newTerminalPerContainer(containerName, options);
return termWidget;
}

throw new Error('Unable to create new terminal widget');
}

get all(): TerminalWidget[] {
return this.widgetManager.getWidgets(REMOTE_TERMINAL_WIDGET_FACTORY_ID) as TerminalWidget[];
}

async registerMenus(menus: MenuModelRegistry) {
const serverUrl = <string | undefined> await this.termApiEndPointProvider();
if (serverUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { REMOTE_TERMINAL_WIDGET_FACTORY_ID, RemoteTerminalWidgetFactoryOptions } from '../terminal-widget/remote-terminal-widget';
import {CHEWorkspaceService} from '../../common/workspace-service';
import {TerminalApiEndPointProvider} from '../server-definition/terminal-proxy-creator';
import {TerminalService} from '@theia/terminal/lib/browser/base/terminal-service';
import {TerminalWidget, TerminalWidgetOptions} from '@theia/terminal/lib/browser/base/terminal-widget';
import { RemoteTerminalWidget } from '../terminal-widget/remote-terminal-widget';
import { OpenTerminalHandler } from './exec-terminal-contribution';

@injectable()
export class TerminalQuickOpenService implements TerminalService {
export class TerminalQuickOpenService {

constructor(@inject(QuickOpenService) private readonly quickOpenService: QuickOpenService,
constructor(
@inject(QuickOpenService) private readonly quickOpenService: QuickOpenService,
@inject(WidgetManager) private readonly widgetManager: WidgetManager,
@inject(EnvVariablesServer) protected readonly baseEnvVariablesServer: EnvVariablesServer,
@inject('TerminalApiEndPointProvider') protected readonly termApiEndPointProvider: TerminalApiEndPointProvider,
Expand All @@ -31,34 +32,6 @@ export class TerminalQuickOpenService implements TerminalService {
) {
}

activateTerminal(termWidget: TerminalWidget): void {
const tabBar = this.shell.getTabBarFor(termWidget);
if (!tabBar) {
this.shell.addWidget(termWidget, { area: 'bottom' });
}
this.shell.activateWidget(termWidget.id);
}

async newTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
let containerName;

// todo remove rude casting when will be used theia 0.3.16.
if ((options as any).attributes) {
containerName = (options as any).attributes['CHE_MACHINE_NAME'];
}

if (!containerName) {
containerName = await this.workspaceService.findEditorMachineName();
}

if (containerName) {
const termWidget = await this.newTerminalPerContainer(containerName, options);
return termWidget;
}

throw new Error('Unable to create new terminal widget');
}

public async newTerminalPerContainer(containerName: string, options?: TerminalWidgetOptions): Promise<TerminalWidget> {
try {
const workspaceId = <string>await this.baseEnvVariablesServer.getValue('CHE_WORKSPACE_ID').then(v => v ? v.value : undefined);
Expand All @@ -78,7 +51,7 @@ export class TerminalQuickOpenService implements TerminalService {
throw new Error('Unable to create new terminal for machine: ' + containerName);
}

async displayListMachines() {
async displayListMachines(doOpen: OpenTerminalHandler) {
const items: QuickOpenItem[] = [];
const machines = await this.workspaceService.getMachineList();

Expand All @@ -88,14 +61,12 @@ export class TerminalQuickOpenService implements TerminalService {
continue;
}
items.push(new NewTerminalItem(machineName, async (newTermItemFunc) => {
const termWidget = await this.newTerminalPerContainer(newTermItemFunc.machineName);
this.activateTerminal(termWidget);
termWidget.start();
doOpen(newTermItemFunc.machineName);
}));
}
}

this.open(items, 'Select machine to create new terminal');
this.showTerminalItems(items, 'Select machine to create new terminal');
}

private getOpts(placeholder: string, fuzzyMatchLabel: boolean = true): QuickOpenOptions {
Expand All @@ -106,7 +77,7 @@ export class TerminalQuickOpenService implements TerminalService {
});
}

private open(items: QuickOpenItem | QuickOpenItem[], placeholder: string): void {
private showTerminalItems(items: QuickOpenItem | QuickOpenItem[], placeholder: string): void {
this.quickOpenService.open(this.getModel(Array.isArray(items) ? items : [items]), this.getOpts(placeholder));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
workspaceService.findTerminalServer().then(server => {
if (server) {
bind(TerminalWidget).to(RemoteTerminalWidget).inTransientScope();
rebind(TerminalService).toService(TerminalQuickOpenService);
rebind(TerminalService).toService(ExecTerminalFrontendContribution);

return resolve(server.url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class RemoteTerminalWidget extends TerminalWidgetImpl {
}, 100);

if (IBaseTerminalServer.validateId(this.terminalId)) {
this.onDidOpenEmitter.fire(undefined);
return this.terminalId;
}
throw new Error('Failed to start terminal' + (id ? ` for id: ${id}.` : '.'));
Expand All @@ -108,6 +109,16 @@ export class RemoteTerminalWidget extends TerminalWidgetImpl {
this.connectSocket(this.terminalId);
}

get processId(): Promise<number> {
return (async () => {
if (!IBaseTerminalServer.validateId(this.terminalId)) {
throw new Error('terminal is not started');
}
// Exec server side unable to return real process pid. This information is encapsulated.
return this.terminalId;
})();
}

protected connectSocket(id: number) {
const waitForRemoteConnection = this.waitForRemoteConnection = new Deferred<WebSocket>();
const socket = this.createWebSocket(id.toString());
Expand All @@ -119,7 +130,7 @@ export class RemoteTerminalWidget extends TerminalWidgetImpl {

const sendListener = (data) => socket.send(data);
this.term.on('data', sendListener);
socket.onmessage = ev => this.term.write(ev.data);
socket.onmessage = ev => this.write(ev.data);

this.toDisposeOnConnect.push(Disposable.create(() => {
this.term.off('data', sendListener);
Expand Down Expand Up @@ -183,7 +194,9 @@ export class RemoteTerminalWidget extends TerminalWidgetImpl {
const cols = this.term.cols;
const rows = this.term.rows;

this.termServer.resize({id: this.terminalId, cols, rows});
if (this.termServer) {
this.termServer.resize({id: this.terminalId, cols, rows});
}
}

sendText(text: string): void {
Expand Down
Loading

0 comments on commit 348956e

Please sign in to comment.