diff --git a/plugins/c9.cli.bridge/bridge_commands.js b/plugins/c9.cli.bridge/bridge_commands.js index 8f202a93..1ec548ad 100644 --- a/plugins/c9.cli.bridge/bridge_commands.js +++ b/plugins/c9.cli.bridge/bridge_commands.js @@ -42,9 +42,6 @@ define(function(require, exports, module) { case "pipeData": updatePipe(message, e.respond); break; - case "pipeClosed": - closePipe(message, e.respond); - break; case "ping": e.respond(null, true); break; @@ -75,33 +72,26 @@ define(function(require, exports, module) { } /***** Methods *****/ - var pipeTab; - var pipeClosed = true; - function createPipe(message, callback) { - if(pipeClosed) - { - tabManager.once("ready", function(){ - tabManager.open({focus:true, editorType: "ace"}, function(err, tab){ - pipeTab = tab; - pipeTab.document.value += ""; - pipeClosed = false; - }); - }); - } - + tabManager.once("ready", function(){ + tabManager.open( { + focus: true, + editorType: "ace" + }, function(err, tab) { + if (err) + return callback(err); + callback(null, tab.name); + }); + }); } - function updatePipe(message, callback){ - console.log(message.data); - pipeTab.document.value += message.data.toString();; + function updatePipe(message, callback) { + tabManager.once("ready", function() { + tabManager.findTab(message.tab).document.value += message.data; + callback(null, true); + }); } - function closePipe(message, callback){ - pipeClosed = true; - } - - function open(message, callback) { var i = -1; var tabs = []; diff --git a/plugins/c9.cli.open/open.js b/plugins/c9.cli.open/open.js index d7f7a271..a89bb42a 100755 --- a/plugins/c9.cli.open/open.js +++ b/plugins/c9.cli.open/open.js @@ -139,21 +139,34 @@ define(function(require, exports, module) { } function openWithPipe(callback) { - var stdin = process.openStdin(); - var tab; - - bridge.send({ type: "pipe" }, function(){}); - - stdin.on("data", function(chunk){ - var textChunk = decoder.write(chunk); - bridge.send({ type: "pipeData", data: textChunk}, function(err, message) { - + bridge.send({ type: "pipe" }, function(err, response) { + if (err) { + console.log(err.message); + return; + } + + var stdin = process.openStdin(); + var finished = false; + stdin.on("data", function(chunk) { + finished = false; + bridge.send({ + type: "pipeData", + data: decoder.write(chunk), + tab: response + }, function(err, message) { + // Dunno why, but this always returns No Response... + // Escaping that error so end users aren't confused... + if (err && err.message !== "No Response") + console.log(err.message); + finished = true; + }); }); - }); - - stdin.on("end", function(){ - bridge.send({ type: "pipeClosed"}, function(err, message) { - process.exit(40); + stdin.on("end", function() { + (function retry() { + if(finished) + process.exit(40); + setTimeout(retry, 100); + })(); }); }); }