diff --git a/plugins/c9.cli.bridge/bridge_commands.js b/plugins/c9.cli.bridge/bridge_commands.js index 1952f719..8f202a93 100644 --- a/plugins/c9.cli.bridge/bridge_commands.js +++ b/plugins/c9.cli.bridge/bridge_commands.js @@ -36,6 +36,15 @@ define(function(require, exports, module) { case "open": open(message, e.respond); break; + case "pipe": + createPipe(message, e.respond); + break; + case "pipeData": + updatePipe(message, e.respond); + break; + case "pipeClosed": + closePipe(message, e.respond); + break; case "ping": e.respond(null, true); break; @@ -66,6 +75,32 @@ 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; + }); + }); + } + + } + + function updatePipe(message, callback){ + console.log(message.data); + pipeTab.document.value += message.data.toString();; + } + + function closePipe(message, callback){ + pipeClosed = true; + } + function open(message, callback) { var i = -1; diff --git a/plugins/c9.cli.open/open.js b/plugins/c9.cli.open/open.js index d186f500..d7f7a271 100755 --- a/plugins/c9.cli.open/open.js +++ b/plugins/c9.cli.open/open.js @@ -11,6 +11,8 @@ define(function(require, exports, module) { var fs = require("fs"); var PATH = require("path"); + var StringDecoder = require('string_decoder').StringDecoder; + var decoder = new StringDecoder("utf8"); /***** Initialization *****/ @@ -25,19 +27,28 @@ define(function(require, exports, module) { cmd.addCommand({ name: "open", info: " Opens a file or directory.", - usage: "[--wait] ", + usage: "[--wait] [--pipe] [--stream] ", options: { "wait": { description: "Wait until the file(s) are closed", "default": false, "boolean": true + }, + "pipe": { + description: "Pipe data from a command into c9", + "default": false, + "boolean": true } }, check: function(argv) { - if (argv._.length < 2 && !argv["path"]) + if (argv._.length < 2 && !argv["path"] && !argv.pipe) throw new Error("Missing path"); }, exec: function(argv) { + if(argv.pipe) { + openWithPipe(function(){}); + return; + } open( argv._.slice(1), // Remove "open" from the paths argv.wait, @@ -49,6 +60,7 @@ define(function(require, exports, module) { /***** Methods *****/ function open(paths, wait, callback) { + try { paths = paths.map(function(path) { var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory(); @@ -126,6 +138,26 @@ 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) { + + }); + }); + + stdin.on("end", function(){ + bridge.send({ type: "pipeClosed"}, function(err, message) { + process.exit(40); + }); + }); + } + function startCloud9Local(opts, callback) { if (options.platform == "darwin") { proc.spawn("open", {