diff --git a/modules/orionode/lib/orionode.client/tty/shell.js b/modules/orionode/lib/orionode.client/tty/shell.js index cb88468013..146b71df09 100644 --- a/modules/orionode/lib/orionode.client/tty/shell.js +++ b/modules/orionode/lib/orionode.client/tty/shell.js @@ -1,6 +1,6 @@ /******************************************************************************* * @license - * Copyright (c) 2016 IBM Corporation and others. + * Copyright (c) 2016, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution @@ -9,7 +9,6 @@ * Contributors: IBM Corporation - initial API and implementation ******************************************************************************/ /*eslint-env browser, amd*/ -/*global Terminal*/ define([ "socket.io/socket.io", "requirejs/domReady", @@ -17,8 +16,9 @@ define([ 'orion/widgets/input/SettingsSelect', 'orion/commands', "orion/PageUtil", - "xterm/xterm" -], function(io, onReady, DropDownMenu, SettingsSelect, mCommands, PageUtil, Terminal) { + "xterm/xterm", + 'tty/shellIntegrationCmd' +], function(io, onReady, DropDownMenu, SettingsSelect, mCommands, PageUtil, Terminal, mShellIntegrationCmd) { var term, serviceRegistry; var colorScheme = "Dark"; @@ -86,6 +86,10 @@ define([ }); socket.on('data', function(data) { term.write(data); + var apc = parseAPC(data); + if (apc) { + mShellIntegrationCmd.execute(socket, apc.split('\r\n')); + } }); socket.on('disconnect', function() { term.destroy(); @@ -101,6 +105,31 @@ define([ return result.length > 0 ? result : null; } + var pendingAPC = ""; + function parseAPC(data) { + if (pendingAPC) { + var end = data.indexOf(String.fromCharCode(27)); + if (end > -1) { + var bakPendingAPC = pendingAPC; + pendingAPC = ""; + return bakPendingAPC + data.substr(0, end) + } else { + pendingAPC += data; + } + } else { + var apcStart = data.indexOf(String.fromCharCode(27) + '_'); + if (apcStart > -1) { + var end = data.indexOf(String.fromCharCode(27), apcStart + 2); + if (end > -1) { + return data.substr(apcStart + 2, end - apcStart - 2); + } else { + pendingAPC += data.substr(apcStart + 2); + } + } + } + return null; + } + function changeScheme(schemeName) { var t; if (term !== null) { diff --git a/modules/orionode/lib/orionode.client/tty/shellIntegrationCmd.js b/modules/orionode/lib/orionode.client/tty/shellIntegrationCmd.js new file mode 100644 index 0000000000..58ec8059b3 --- /dev/null +++ b/modules/orionode/lib/orionode.client/tty/shellIntegrationCmd.js @@ -0,0 +1,39 @@ +/******************************************************************************* + * @license + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 + * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution + * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +/*eslint-env browser, amd*/ +/*global Terminal*/ +define([], function() { + + /** + * Execute integration command from shell + * @param {Socket.IO.Client} socket + * @param {Array.} args + */ + function execute(socket, args) { + switch (args[0]) { + case 'edit': + edit(socket, args); + break; + } + } + + function edit(socket, args) { + var absPath = args[1]; + socket.emit('absolute2project', absPath, function(projPath) { + var contextPath = new URL('..', location.href).pathname; + window.open('../edit/edit.html#' + contextPath + '/file' + encodeURIComponent(projPath.replace('#', '%23'))); + }); + } + + return { + execute: execute + }; +}); \ No newline at end of file diff --git a/modules/orionode/lib/tty_orion_integration.sh b/modules/orionode/lib/tty_orion_integration.sh new file mode 100644 index 0000000000..7d91cb6755 --- /dev/null +++ b/modules/orionode/lib/tty_orion_integration.sh @@ -0,0 +1,15 @@ +#!/bin/sh +function orion() { + printf "\33_"; + if [ $1 == "edit" ]; then + echo "edit"; + [[ $2 = /* ]] && echo "$2" || echo "$PWD/${2#./}"; + else + for param in "$@"; do + echo "$param"; + done + fi + printf "\33\134"; + echo "Executing: $@"; +} +clear; \ No newline at end of file diff --git a/modules/orionode/lib/tty_shell.js b/modules/orionode/lib/tty_shell.js index 766ee37a20..e55075eef6 100644 --- a/modules/orionode/lib/tty_shell.js +++ b/modules/orionode/lib/tty_shell.js @@ -126,6 +126,19 @@ exports.install = function(options) { : sock.emit('data', data); }); + if (process.platform !== 'win32') { + var orionIntegrationScriptPath = path.resolve('./lib/tty_orion_integration.sh'); + terminal.write('. "' + orionIntegrationScriptPath + '"\n'); + } + + sock.on('absolute2project', function(absolute, callback) { + if (absolute.startsWith(userWorkspaceDir)) { + callback(absolute.substr(userWorkspaceDir.length)); + } else { + callback(null); + } + }); + logger.info('Created new %s (fd: %d, pid: %d)', shell, terminal.fd,