mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-28 22:35:45 +01:00
Allow asynchronous io.system() calls. Fix :help intro.
This commit is contained in:
@@ -2170,7 +2170,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
|
|
||||||
if (localPrefs.get("first-run", true))
|
if (localPrefs.get("first-run", true))
|
||||||
dactyl.timeout(function () {
|
dactyl.timeout(function () {
|
||||||
localPrefs.set("first-run", config.version);
|
localPrefs.set("first-run", false);
|
||||||
this.withSavedValues(["forceNewTab"], function () {
|
this.withSavedValues(["forceNewTab"], function () {
|
||||||
this.forceNewTab = true;
|
this.forceNewTab = true;
|
||||||
this.help();
|
this.help();
|
||||||
|
|||||||
@@ -616,6 +616,8 @@ function memoize(obj, key, getter) {
|
|||||||
let get = __lookupGetter__.call(obj, prop);
|
let get = __lookupGetter__.call(obj, prop);
|
||||||
if (get)
|
if (get)
|
||||||
memoize(res, prop, get);
|
memoize(res, prop, get);
|
||||||
|
else if (obj[prop] instanceof Class.Property)
|
||||||
|
Object.defineProperty(res, prop, obj[prop].init(prop, obj) || obj[prop]);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ var IO = Module("io", {
|
|||||||
* @param {File|string} program The program to run.
|
* @param {File|string} program The program to run.
|
||||||
* @param {[string]} args An array of arguments to pass to *program*.
|
* @param {[string]} args An array of arguments to pass to *program*.
|
||||||
*/
|
*/
|
||||||
run: function (program, args, blocking) {
|
run: function (program, args, blocking, self) {
|
||||||
args = args || [];
|
args = args || [];
|
||||||
|
|
||||||
let file = this.pathSearch(program);
|
let file = this.pathSearch(program);
|
||||||
@@ -447,7 +447,7 @@ var IO = Module("io", {
|
|||||||
function () {
|
function () {
|
||||||
if (!process.isRunning) {
|
if (!process.isRunning) {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
util.trapErrors(blocking);
|
util.trapErrors(blocking, self, process.exitValue);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
100, services.Timer.TYPE_REPEATING_SLACK);
|
100, services.Timer.TYPE_REPEATING_SLACK);
|
||||||
@@ -471,12 +471,14 @@ var IO = Module("io", {
|
|||||||
*
|
*
|
||||||
* @param {string} command The command to run.
|
* @param {string} command The command to run.
|
||||||
* @param {string} input Any input to be provided to the command on stdin.
|
* @param {string} input Any input to be provided to the command on stdin.
|
||||||
* @returns {object}
|
* @param {function(object)} callback A callback to be called when
|
||||||
|
* the command completes. @optional
|
||||||
|
* @returns {object|null}
|
||||||
*/
|
*/
|
||||||
system: function (command, input) {
|
system: function (command, input, callback) {
|
||||||
util.dactyl.echomsg(_("io.callingShell", command), 4);
|
util.dactyl.echomsg(_("io.callingShell", command), 4);
|
||||||
|
|
||||||
function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"';
|
function escape(str) '"' + String.replace(str, /[\\"$]/g, "\\$&") + '"';
|
||||||
|
|
||||||
return this.withTempFiles(function (stdin, stdout, cmd) {
|
return this.withTempFiles(function (stdin, stdout, cmd) {
|
||||||
if (input instanceof File)
|
if (input instanceof File)
|
||||||
@@ -484,6 +486,20 @@ var IO = Module("io", {
|
|||||||
else if (input)
|
else if (input)
|
||||||
stdin.write(input);
|
stdin.write(input);
|
||||||
|
|
||||||
|
function result(status, output) ({
|
||||||
|
__noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args),
|
||||||
|
valueOf: function () this.output,
|
||||||
|
output: output.replace(/^(.*)\n$/, "$1"),
|
||||||
|
returnValue: status,
|
||||||
|
toString: function () this.output
|
||||||
|
});
|
||||||
|
|
||||||
|
function async(status) {
|
||||||
|
let output = stdout.read();
|
||||||
|
[stdin, stdout, cmd].forEach(function (f) f.exists() && f.remove(false));
|
||||||
|
callback(result(status, output));
|
||||||
|
}
|
||||||
|
|
||||||
let shell = io.pathSearch(storage["options"].get("shell").value);
|
let shell = io.pathSearch(storage["options"].get("shell").value);
|
||||||
let shcf = storage["options"].get("shellcmdflag").value;
|
let shcf = storage["options"].get("shellcmdflag").value;
|
||||||
util.assert(shell, _("error.invalid", "'shell'"));
|
util.assert(shell, _("error.invalid", "'shell'"));
|
||||||
@@ -494,23 +510,17 @@ var IO = Module("io", {
|
|||||||
// TODO: implement 'shellredir'
|
// TODO: implement 'shellredir'
|
||||||
if (util.OS.isWindows && !/sh/.test(shell.leafName)) {
|
if (util.OS.isWindows && !/sh/.test(shell.leafName)) {
|
||||||
command = "cd /D " + this.cwd.path + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path;
|
command = "cd /D " + this.cwd.path + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path;
|
||||||
var res = this.run(shell, shcf.split(/\s+/).concat(command), true);
|
var res = this.run(shell, shcf.split(/\s+/).concat(command), callback ? async : true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmd.write("cd " + escape(this.cwd.path) + "\n" +
|
cmd.write("cd " + escape(this.cwd.path) + "\n" +
|
||||||
["exec", ">" + escape(stdout.path), "2>&1", "<" + escape(stdin.path),
|
["exec", ">" + escape(stdout.path), "2>&1", "<" + escape(stdin.path),
|
||||||
escape(shell.path), shcf, escape(command)].join(" "));
|
escape(shell.path), shcf, escape(command)].join(" "));
|
||||||
res = this.run("/bin/sh", ["-e", cmd.path], true);
|
res = this.run("/bin/sh", ["-e", cmd.path], callback ? async : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return callback ? true : result(res, stdout.read());
|
||||||
__noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args),
|
}, this, true);
|
||||||
valueOf: function () this.output,
|
|
||||||
output: stdout.read().replace(/^(.*)\n$/, "$1"),
|
|
||||||
returnValue: res,
|
|
||||||
toString: function () this.output
|
|
||||||
};
|
|
||||||
}) || "";
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -533,7 +543,7 @@ var IO = Module("io", {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (!checked || res !== true)
|
if (!checked || res !== true)
|
||||||
args.forEach(function (f) f && f.remove(false));
|
args.forEach(function (f) f.remove(false));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user