Skip to content

Commit

Permalink
version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Aug 31, 2012
1 parent 1b26469 commit cf605b7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ FILES = chrome/ \

all:
rm -f jsterm.xpi && zip -r jsterm.xpi $(FILES)
wget --post-file=$(PWD)/jsterm.xpi http://localhost:8888/
wget --post-file=$(PWD)/jsterm.xpi http://localhost:8889/
2 changes: 1 addition & 1 deletion bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ JSTerm.prototype = {


let JSTermGlobalHistory = {
_limit: 5,
_limit: 100, // Should be a pref
_entries: [],

_cut: function() {
Expand Down
72 changes: 52 additions & 20 deletions chrome/jsterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let JSTermUI = {
exec: this.undock.bind(this)},
{name: ":dock", help: "Move the terminal in browser",
exec: this.dock.bind(this)},
{name: "ls", hidden: true, exec: this.ls.bind(this)},
];
},

Expand Down Expand Up @@ -90,7 +91,7 @@ let JSTermUI = {
defaultOutputText = aDefaultContent.output;
} else {
defaultInputText = "";
defaultOutputText = "// type ':help' for help\n// Report bug here: https://github.com/paulrouget/firefox-jsterm";
defaultOutputText = "// type ':help' for help\n// Report bug here: https://github.com/paulrouget/firefox-jsterm/issues";
}

this.history = new JSTermLocalHistory(aGlobalHistory);
Expand Down Expand Up @@ -142,14 +143,29 @@ let JSTermUI = {
return sb;
},

print: function(msg = "", startWith = "\n") {
print: function(msg = "", startWith = "\n", isAnObject = false, object = null) {
clearTimeout(this.printTimeout);
this.printQueue += startWith + msg;
this.printTimeout = setTimeout(function printCommit() {
this.printedSomething = true;
this.output.setText(this.printQueue, this.output.getCharCount());
this.printQueue = "";
}.bind(this), 0);

if (isAnObject) {
// let's do that synchronously, because we want to add a mark
if (this.printQueue) {
// flush
this.output.setText(this.printQueue, this.output.getCharCount());
this.printQueue = "";
}
this.output.setText(startWith + msg, this.output.getCharCount());
let line = this.output.getLineCount() - 1;
this.objects.set(line, object);
this.markRange(line);

} else {
this.printQueue += startWith + msg;

this.printTimeout = setTimeout(function printCommit() {
this.output.setText(this.printQueue, this.output.getCharCount());
this.printQueue = "";
}.bind(this), 0);
}
},

initOutput: function() {
Expand Down Expand Up @@ -208,15 +224,20 @@ let JSTermUI = {
},

newEntry: function(code) {
if (this.evaluating) return;
this.evaluating = true;

this.history.stopBrowsing();
this.history.add(code);

this.input.setText("");
this.multiline = false;
this.printedSomething = false;

this.printCount = 0;

if (code == "") {
this.print();
this.onceEntryResultPrinted();
return;
}

Expand All @@ -225,6 +246,7 @@ let JSTermUI = {
for (let cmd of this.commands) {
if (cmd.name == code) {
cmd.exec();
this.onceEntryResultPrinted();
return;
}
}
Expand All @@ -237,20 +259,25 @@ let JSTermUI = {
}

this.dumpEntryResult(result, error, code);
this.onceEntryResultPrinted();
},

onceEntryResultPrinted: function() {
/* Ugly hack to scrollback */
this.output.editorElement.contentDocument.querySelector("iframe")
.contentDocument.querySelector(".view").scrollLeft = 0;

/* Clear Selection if any */
let cursor = this.output.getLineStart(this.output.getLineCount() - 1);
this.output.setSelection(cursor, cursor);

this.evaluating = false;
},

dumpEntryResult: function(result, error, code) {
if (error) {
error = error.toString();
if (this.isMultiline(error) || this.isMultiline(code) || this.printedSomething) {
if (this.isMultiline(error) || this.isMultiline(code)) {
this.print("/* error:\n" + error + "\n*/");
} else {
this.print(" // error: " + error, startWith = "");
Expand All @@ -275,7 +302,7 @@ let JSTermUI = {
}

if (code == resultStr ||
(result == undefined && this.printedSomething)) {
(result == undefined)) {
return;
}

Expand All @@ -290,20 +317,15 @@ let JSTermUI = {
resultStr = "\n" + resultStr;
}
} else {
if (this.isMultiline(code) || this.printedSomething) {
if (this.isMultiline(code)) {
resultStr = "\n// " + resultStr;
} else {
resultStr = " // " + resultStr;
}
}

this.print(resultStr, startWith = "");
this.print(resultStr, startWith = "", isAnObject, isAnObject ? result : null);

if (isAnObject) {
let line = this.output.getLineCount() - 1;
this.objects.set(line, result);
this.markRange(line);
}
},

isMultiline: function(text) {
Expand Down Expand Up @@ -331,8 +353,12 @@ let JSTermUI = {
text += "\n * ";
text += "\n * Commands:";
for (let cmd of this.commands) {
text += "\n * " + cmd.name + " - " + cmd.help;
if (cmd.help) {
text += "\n * " + cmd.name + " - " + cmd.help;
}
}
text += "\n * ";
text += "\n * Bugs? Suggestions? Questions? -> https://github.com/paulrouget/firefox-jsterm/issues";
text += "\n */";
this.print(text);
},
Expand Down Expand Up @@ -473,6 +499,10 @@ let JSTermUI = {
this.manager.moveTermTo(this.browser, "in_browser");
}
},

ls: function() {
this.print("// Did you just type \"ls\"? You know this is not a unix shell, right?");
},
}


Expand All @@ -497,7 +527,9 @@ JSCompletion.prototype = {
let JSKeywords = "break delete case do catch else class export continue finally const for debugger function default if import this in throw instanceof try let typeof new var return void super while switch with";
this.dictionnary = JSKeywords.split(" ");
for (let cmd of JSTermUI.commands) {
this.dictionnary.push(cmd.name);
if (!cmd.hidden) {
this.dictionnary.push(cmd.name);
}
}
},
handleKeys: function(e) {
Expand Down
Binary file modified jsterm.xpi
Binary file not shown.

0 comments on commit cf605b7

Please sign in to comment.