Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Jul 18, 2012
1 parent c3db820 commit 9374560
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
3 changes: 2 additions & 1 deletion chrome/jsterm.css
Expand Up @@ -10,11 +10,12 @@ window {
color: #8fa1b2;
font-family: Monaco, monospace;
font-weight: lighter;
font-size: 10px;
font-size: 12px;
}

#editors-container {
padding: 5px;
overflow-y: auto;
}

#prompt {
Expand Down
47 changes: 27 additions & 20 deletions chrome/jsterm.js
Expand Up @@ -10,8 +10,11 @@ Cu.import("resource:///modules/WebConsoleUtils.jsm");
* . checkbox status
* . use getLineDelimiter
* . Complete on keywords (function)
* . console.log
* . highlight common DOM keywords
* . console.log / print()
* . save history and share it
* . better enter/shift-enter thing
* . overflow-x
*/

const JSTERM_MARK = "orion.annotation.jstermobject";
Expand Down Expand Up @@ -63,7 +66,7 @@ let JSTermUI = {
let outputContainer = document.querySelector("#output-container");
this.inputContainer = document.querySelector("#input-container");
this.output.init(outputContainer, {
initialText: "/**\n * 'Shift-Return' to toggle multiline-mode\n */\n",
initialText: "// type ':help' for help",
mode: SourceEditor.MODES.JAVASCRIPT,
readOnly: true,
theme: "chrome://jsterm/content/orion.css",
Expand All @@ -82,7 +85,7 @@ let JSTermUI = {

switchToChromeMode: function() {
let label = document.querySelector("#completion-candidates > label");
this.sb = Cu.Sandbox(this.chrome, {sandboxPrototype: this.chrome, wantXrays: false});
this.sb = this.buildSandbox(this.chrome);
this.output.setText("\n:chrome // Switched to chrome mode.", this.output.getCharCount());
if (this.completion) this.completion.destroy();
this.completion = new JSCompletion(this.input, label, this.sb);
Expand All @@ -92,7 +95,7 @@ let JSTermUI = {
switchToContentMode: function() {
let label = document.querySelector("#completion-candidates > label");
let needMessage = !!this.sb;
this.sb = Cu.Sandbox(this.content, {sandboxPrototype: this.content, wantXrays: false});
this.sb = this.buildSandbox(this.content);
if (this.completion) this.completion.destroy();
this.completion = new JSCompletion(this.input, label, this.sb);
if (needMessage) {
Expand All @@ -101,6 +104,14 @@ let JSTermUI = {
this.inputContainer.classList.remove("chrome");
},

buildSandbox: function(win) {
let sb = Cu.Sandbox(win, {sandboxPrototype: win, wantXrays: false});
sb.print = function(msg) {
dump(msg + "\n");
}
return sb;
},

initOutput: function() {
this.makeEditorFitContent(this.output);
this.ensureInputIsAlwaysVisible(this.output);
Expand Down Expand Up @@ -248,8 +259,13 @@ let JSTermUI = {
}


let isAnObject = (typeof result) == "object";
let resultStr = result.toString();

if (isAnObject) {
resultStr += " (click to inspect)";
}

if (code == resultStr) {
this.output.setText("\n" + code, this.output.getCharCount());
} else if (code) {
Expand All @@ -266,7 +282,6 @@ let JSTermUI = {
this.output.setText("\n" + code + " // " + resultStr, this.output.getCharCount());
}
}
let isAnObject = (typeof result) == "object";
if (isAnObject) {
let line = this.output.getLineCount() - 1;
this.objects.set(line, result);
Expand All @@ -290,9 +305,8 @@ let JSTermUI = {

help: function() {
let text = "\n:help\n/**";
text += "\n * 'Return' to evaluate line,";
text += "\n * 'Shift+Return' to enter multiline mode,";
text += "\n * 'Shift+Return' to valide multiline content,";
text += "\n * 'Return' to evaluate entry,";
text += "\n * 'Shift+Return' to add a line,";
text += "\n * 'Tab' for autocompletion,";
text += "\n * 'up/down' to browser history,";
text += "\n * ";
Expand All @@ -308,18 +322,11 @@ let JSTermUI = {
let code = this.input.getText();

if (e.keyCode == 13 && e.shiftKey) {
if (!this.multiline) {
this.multiline = true;
} else {
this.multiline = false;
e.preventDefault();
e.stopPropagation()
this.newEntry(code);
}
this.multiline = true;
return;
}

if (!this.multiline && e.keyCode == 13) {
if (e.keyCode == 13) {
e.stopPropagation();
e.preventDefault();
this.newEntry(code);
Expand Down Expand Up @@ -466,12 +473,12 @@ JSCompletion.prototype = {
// if several candidate

let commonPrefix = candidates.matches.reduce(function(commonPrefix, nextValue) {
if (!commonPrefix)
return nextValue;

if (commonPrefix == "")
return "";

if (!commonPrefix)
return nextValue;

if (commonPrefix.length > nextValue.length) {
commonPrefix = commonPrefix.substr(0, nextValue.length);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/jsterm.xul
Expand Up @@ -15,7 +15,7 @@
<script type="application/javascript" src="jsterm.js"/>
<hbox flex="1">
<vbox flex="1">
<vbox id="editors-container" flex="1" style="overflow-y:auto" onclick="JSTermUI.focus()">
<vbox id="editors-container" flex="1" onclick="JSTermUI.focus()">
<hbox flex="1" id="output-container"/>
<hbox flex="1" id="input-container"><label id="prompt" value=""/></hbox>
</vbox>
Expand Down
8 changes: 6 additions & 2 deletions chrome/orion.css
Expand Up @@ -43,8 +43,12 @@
text-align: start;
}

.annotationLine.object > span:first-of-type {
text-decoration: underline;
.annotationLine.object {
/*
text-decoration: underline;
-moz-text-decoration-color: grey;
-moz-text-decoration-style: dotted;
*/
cursor: pointer;
}

Expand Down

0 comments on commit 9374560

Please sign in to comment.