1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 20:37:58 +01:00

Death to E4X and stuff.

This commit is contained in:
Kris Maglione
2012-12-16 19:58:35 -08:00
parent 1aaf3f75aa
commit 2f0af0a3f1
5 changed files with 13 additions and 132 deletions

View File

@@ -4,7 +4,7 @@
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
/* use strict */ "use strict";
/** @scope modules */ /** @scope modules */
@@ -664,12 +664,8 @@ var CommandLine = Module("commandline", {
* @param {XML} xml The output as an E4X XML object. * @param {XML} xml The output as an E4X XML object.
*/ */
commandOutput: function commandOutput(xml) { commandOutput: function commandOutput(xml) {
XML.ignoreWhitespace = XML.prettyPrinting = false;
if (!this.command) if (!this.command)
this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
else if (isXML(xml))
this.echo(<><div xmlns={XHTML}>:{this.command}</div>&#x0d;{xml}</>,
this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
else else
this.echo([["div", { xmlns: "html" }, ":" + this.command], "\n", xml], this.echo([["div", { xmlns: "html" }, ":" + this.command], "\n", xml],
this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
@@ -765,7 +761,7 @@ var CommandLine = Module("commandline", {
this._lastEcho = null; this._lastEcho = null;
else { else {
if (this.widgets.message && this.widgets.message[1] == this._lastEcho) if (this.widgets.message && this.widgets.message[1] == this._lastEcho)
mow.echo(<span highlight="Message">{this._lastEcho}</span>, mow.echo(["span", { highlight: "Message" }, this._lastEcho],
this.widgets.message[0], true); this.widgets.message[0], true);
if (action === this._echoLine && !(flags & this.FORCE_MULTILINE) if (action === this._echoLine && !(flags & this.FORCE_MULTILINE)
@@ -1624,10 +1620,10 @@ var CommandLine = Module("commandline", {
commandline.echo(message.message, message.highlight, commandline.FORCE_SINGLELINE); commandline.echo(message.message, message.highlight, commandline.FORCE_SINGLELINE);
} }
else if (commandline._messageHistory.length > 1) { else if (commandline._messageHistory.length > 1) {
XML.ignoreWhitespace = false;
commandline.commandOutput( commandline.commandOutput(
template.map(commandline._messageHistory.messages, function (message) template_.map(commandline._messageHistory.messages, function (message)
<div highlight={message.highlight + " Message"}>{message.message}</div>)); ["div", { highlight: message.highlight + " Message" },
message.message]));
} }
}, },
{ argCount: "0" }); { argCount: "0" });

View File

@@ -4,7 +4,7 @@
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
/* use strict */ // "use strict";
/** @scope modules */ /** @scope modules */
@@ -281,7 +281,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
for (let obj in values(results)) { for (let obj in values(results)) {
let res = dactyl.generateHelp(obj, null, null, true); let res = dactyl.generateHelp(obj, null, null, true);
if (!haveTag(obj.helpTag)) if (!haveTag(obj.helpTag))
res[1].@tag = obj.helpTag; res[0][1].tag = obj.helpTag;
yield res; yield res;
} }
@@ -418,7 +418,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (isObject(str) && "echoerr" in str) if (isObject(str) && "echoerr" in str)
str = str.echoerr; str = str.echoerr;
else if (isinstance(str, ["Error", FailedAssertion]) && str.fileName) else if (isinstance(str, ["Error", FailedAssertion]) && str.fileName)
str = util.Magic([str.fileName.replace(/^.* -> /, ""), ": ", str.lineNumber, ": ", str].join("")); str = [str.fileName.replace(/^.* -> /, ""), ": ", str.lineNumber, ": ", str].join("");
if (options["errorbells"]) if (options["errorbells"])
dactyl.beep(); dactyl.beep();
@@ -661,110 +661,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @returns {string} * @returns {string}
*/ */
generateHelp: function generateHelp(obj, extraHelp, str, specOnly) { generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
default xml namespace = "";
let link, tag, spec;
link = tag = spec = util.identity;
let args = null;
if (obj instanceof Command) {
link = function (cmd) <ex>{cmd}</ex>;
args = obj.parseArgs("", CompletionContext(str || ""));
tag = function (cmd) <>:{cmd}</>;
spec = function (cmd) <>{
obj.count ? <oa>count</oa> : <></>
}{
cmd
}{
obj.bang ? <oa>!</oa> : <></>
}</>;
}
else if (obj instanceof Map) {
spec = function (map) obj.count ? <><oa>count</oa>{map}</> : <>{map}</>;
tag = function (map) <>{
let (c = obj.modes[0].char) c ? c + "_" : ""
}{ map }</>;
link = function (map) {
let [, mode, name, extra] = /^(?:(.)_)?(?:<([^>]+)>)?(.*)$/.exec(map);
let k = <k>{extra}</k>;
if (name)
k.@name = name;
if (mode)
k.@mode = mode;
return k;
};
}
else if (obj instanceof Option) {
spec = function () template.map(obj.names, tag, " ");
tag = function (name) <>'{name}'</>;
link = function (opt, name) <o>{name}</o>;
args = { value: "", values: [] };
}
XML.prettyPrinting = false;
XML.ignoreWhitespace = false;
default xml namespace = NS;
// E4X has its warts.
let br = <>
</>;
let res = <res>
<dt>{link(obj.helpTag || tag(obj.name), obj.name)}</dt> <dd>{
template.linkifyHelp(obj.description ? obj.description.replace(/\.$/, "") : "", true)
}</dd></res>;
if (specOnly)
return res.elements();
res.* += <>
<item>
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags>
<spec>{let (name = (obj.specs || obj.names)[0])
spec(template.highlightRegexp(tag(name),
/\[(.*?)\]/g,
function (m, n0) <oa>{n0}</oa>),
name)
}</spec>{
!obj.type ? "" : <>
<type>{obj.type}</type>
<default>{obj.stringDefaultValue}</default></>}
<description>{
obj.description ? br + <p>{template.linkifyHelp(obj.description.replace(/\.?$/, "."), true)}</p> : "" }{
extraHelp ? br + extraHelp : "" }{
!(extraHelp || obj.description) ? br + <p><!--L-->Sorry, no help available.</p> : "" }
</description>
</item></>;
function add(ary) {
res.item.description.* += br +
let (br = br + <> </>)
<><dl>{ br + template.map(ary, function ([a, b]) <><dt>{a}</dt> <dd>{b}</dd></>, br) }
</dl>
</>;
}
if (obj.completer)
add(completion._runCompleter(obj.closure.completer, "", null, args).items
.map(function (i) [i.text, i.description]));
if (obj.options && obj.options.some(function (o) o.description))
add(obj.options.filter(function (o) o.description)
.map(function (o) [
o.names[0],
<>{o.description}{
o.names.length == 1 ? "" :
<> (short name: {
template.map(o.names.slice(1), function (n) <em>{n}</em>, <>, </>)
})</>
}</>
]));
return res.*.toXMLString()
.replace(' xmlns="' + NS + '"', "", "g")
.replace(/^ {12}|[ \t]+$/gm, "")
.replace(/^\s*\n|\n\s*$/g, "") + "\n";
},
_generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
let link, tag, spec; let link, tag, spec;
link = tag = spec = util.identity; link = tag = spec = util.identity;
let args = null; let args = null;

View File

@@ -4,7 +4,7 @@
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
/* use strict */ "use strict";
var MOW = Module("mow", { var MOW = Module("mow", {
init: function init() { init: function init() {
@@ -104,12 +104,6 @@ var MOW = Module("mow", {
this.messages = []; this.messages = [];
} }
// If it's already XML, assume it knows what it's doing.
// Otherwise, white space is significant.
// The problem elsewhere is that E4X tends to insert new lines
// after interpolated data.
XML.ignoreWhitespace = XML.prettyPrinting = false;
highlightGroup = "CommandOutput " + (highlightGroup || ""); highlightGroup = "CommandOutput " + (highlightGroup || "");
if (isObject(data) && !isinstance(data, _) && !DOM.isJSONXML(data)) { if (isObject(data) && !isinstance(data, _) && !DOM.isJSONXML(data)) {
@@ -127,19 +121,13 @@ var MOW = Module("mow", {
} }
this.messages.push(data); this.messages.push(data);
} }
else if (DOM.isJSONXML(data) || isString(data)) { else {
let style = isString(data) ? "pre-wrap" : "nowrap"; let style = isString(data) ? "pre-wrap" : "nowrap";
this.lastOutput = ["div", { style: "white-space: " + style, highlight: highlightGroup }, this.lastOutput = ["div", { style: "white-space: " + style, highlight: highlightGroup },
data]; data];
var output = DOM(this.lastOutput, this.document); var output = DOM(this.lastOutput, this.document);
} }
else {
let style = isString(data) ? "pre-wrap" : "nowrap";
this.lastOutput = <div style="white-space: nowrap" highlight={highlightGroup}>{data}</div>;
var output = DOM(this.lastOutput, this.document);
}
// FIXME: need to make sure an open MOW is closed when commands // FIXME: need to make sure an open MOW is closed when commands
// that don't generate output are executed // that don't generate output are executed

View File

@@ -666,7 +666,7 @@ var Template_ = Module("Template_", {
return this.highlightSubstrings(str, (function () { return this.highlightSubstrings(str, (function () {
for (let res in re.iterate(str)) for (let res in re.iterate(str))
yield [res.index + res.pre.length, res.tag.length]; yield [res.index + res.pre.length, res.tag.length];
})(), template[help ? "HelpLink" : "helpLink"]); })(), this[help ? "HelpLink" : "helpLink"]);
}, },
@@ -779,7 +779,6 @@ var Template_ = Module("Template_", {
break; break;
_i = i; _i = i;
XML.ignoreWhitespace = false;
s.push(str.substring(start, i), s.push(str.substring(start, i),
highlight.apply(this, Array.concat(args || str.substr(i, length)))); highlight.apply(this, Array.concat(args || str.substr(i, length))));
start = i + length; start = i + length;

View File

@@ -22,6 +22,8 @@ var Magic = Class("Magic", {
this.str = str; this.str = str;
}, },
get message() this.str,
toString: function () this.str toString: function () this.str
}); });