kopia lustrzana https://github.com/c9/core
cleaned up code, made better, ready for pull req;
rodzic
1d536ff6c4
commit
ef433b8948
|
@ -42,9 +42,6 @@ define(function(require, exports, module) {
|
||||||
case "pipeData":
|
case "pipeData":
|
||||||
updatePipe(message, e.respond);
|
updatePipe(message, e.respond);
|
||||||
break;
|
break;
|
||||||
case "pipeClosed":
|
|
||||||
closePipe(message, e.respond);
|
|
||||||
break;
|
|
||||||
case "ping":
|
case "ping":
|
||||||
e.respond(null, true);
|
e.respond(null, true);
|
||||||
break;
|
break;
|
||||||
|
@ -75,33 +72,26 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Methods *****/
|
/***** Methods *****/
|
||||||
var pipeTab;
|
|
||||||
var pipeClosed = true;
|
|
||||||
|
|
||||||
function createPipe(message, callback) {
|
function createPipe(message, callback) {
|
||||||
if(pipeClosed)
|
tabManager.once("ready", function(){
|
||||||
{
|
tabManager.open( {
|
||||||
tabManager.once("ready", function(){
|
focus: true,
|
||||||
tabManager.open({focus:true, editorType: "ace"}, function(err, tab){
|
editorType: "ace"
|
||||||
pipeTab = tab;
|
}, function(err, tab) {
|
||||||
pipeTab.document.value += "";
|
if (err)
|
||||||
pipeClosed = false;
|
return callback(err);
|
||||||
});
|
callback(null, tab.name);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePipe(message, callback){
|
function updatePipe(message, callback) {
|
||||||
console.log(message.data);
|
tabManager.once("ready", function() {
|
||||||
pipeTab.document.value += message.data.toString();;
|
tabManager.findTab(message.tab).document.value += message.data;
|
||||||
|
callback(null, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePipe(message, callback){
|
|
||||||
pipeClosed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function open(message, callback) {
|
function open(message, callback) {
|
||||||
var i = -1;
|
var i = -1;
|
||||||
var tabs = [];
|
var tabs = [];
|
||||||
|
|
|
@ -139,21 +139,34 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function openWithPipe(callback) {
|
function openWithPipe(callback) {
|
||||||
var stdin = process.openStdin();
|
bridge.send({ type: "pipe" }, function(err, response) {
|
||||||
var tab;
|
if (err) {
|
||||||
|
console.log(err.message);
|
||||||
bridge.send({ type: "pipe" }, function(){});
|
return;
|
||||||
|
}
|
||||||
stdin.on("data", function(chunk){
|
|
||||||
var textChunk = decoder.write(chunk);
|
var stdin = process.openStdin();
|
||||||
bridge.send({ type: "pipeData", data: textChunk}, function(err, message) {
|
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() {
|
||||||
|
(function retry() {
|
||||||
stdin.on("end", function(){
|
if(finished)
|
||||||
bridge.send({ type: "pipeClosed"}, function(err, message) {
|
process.exit(40);
|
||||||
process.exit(40);
|
setTimeout(retry, 100);
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue