Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

TTY shell interaction (experimental) #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions modules/orionode/lib/orionode.client/tty/shell.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,16 +9,16 @@
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
/*eslint-env browser, amd*/
/*global Terminal*/
define([
"socket.io/socket.io",
"requirejs/domReady",
'orion/widgets/input/DropDownMenu',
'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";
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
39 changes: 39 additions & 0 deletions modules/orionode/lib/orionode.client/tty/shellIntegrationCmd.js
Original file line number Diff line number Diff line change
@@ -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.<string>} 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
};
});
15 changes: 15 additions & 0 deletions modules/orionode/lib/tty_orion_integration.sh
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 13 additions & 0 deletions modules/orionode/lib/tty_shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down