1
1
mirror of https://github.com/kanaka/mal.git synced 2024-07-07 10:26:18 +03:00

JS: switch from josh.js console to jqconsole.

js/web/jqconsole.min.js and web/ansi.css are from
https://github.com/replit/jq-console and licensed MIT.
This commit is contained in:
Joel Martin 2014-04-26 14:19:49 -05:00
parent 9b1563a3fb
commit e439350417
22 changed files with 325 additions and 600 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "js/josh.js"]
path = js/josh.js
url = git://github.com/sdether/josh.js

View File

@ -32,6 +32,7 @@ Java:
- step9_interop
Javascript:
- switch to himera page/styling for online console
Make:
- allow '_' in make variable names

View File

@ -4,9 +4,9 @@ TESTS = tests/types.js tests/reader.js tests/step5_tco.js
SOURCES_BASE = node_readline.js types.js reader.js printer.js
SOURCES_LISP = env.js core.js stepA_more.js
SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
WEB_SOURCES = $(SOURCES:node_readline.js=josh_readline.js)
WEB_SOURCES = $(SOURCES:node_readline.js=jq_readline.js)
all: node_modules mal.js mal_web.js
all: node_modules mal.js web/mal.js
node_modules:
npm install
@ -16,11 +16,11 @@ mal.js: $(SOURCES)
cat $+ | grep -v "= *require('./" >> $@
chmod +x $@
mal_web.js: $(WEB_SOURCES)
web/mal.js: $(WEB_SOURCES)
cat $+ | grep -v "= *require('./" > $@
clean:
rm -f mal.js mal_web.js
rm -f mal.js web/mal.js
.PHONY: stats tests $(TESTS)

@ -1 +0,0 @@
Subproject commit 257237550ce9c02cfc426918845e636c763c49bc

View File

@ -1,420 +0,0 @@
/* ------------------------------------------------------------------------*
* Copyright 2013 Arne F. Claassen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------*/
var Josh = Josh || {};
(function(root, $, _) {
Josh.Shell = function(config) {
config = config || {};
// instance fields
var _console = config.console || (Josh.Debug && root.console ? root.console : {
log: function() {
}
});
var _prompt = config.prompt || 'jsh$';
var _action = config.action || function(str) {
return "<div>No action defined for: " + str + "</div>";
};
var _shell_view_id = config.shell_view_id || 'shell-view';
var _shell_panel_id = config.shell_panel_id || 'shell-panel';
var _input_id = config.input_id || 'shell-cli';
var _blinktime = config.blinktime || 500;
var _history = config.history || new Josh.History();
var _readline = config.readline || new Josh.ReadLine({history: _history, console: _console});
var _active = false;
var _cursor_visible = false;
var _activationHandler;
var _deactivationHandler;
var _cmdHandlers = {
clear: {
exec: function(cmd, args, callback) {
$(id(_input_id)).parent().empty();
callback();
}
},
help: {
exec: function(cmd, args, callback) {
callback(self.templates.help({commands: commands()}));
}
},
history: {
exec: function(cmd, args, callback) {
if(args[0] == "-c") {
_history.clear();
callback();
return;
}
callback(self.templates.history({items: _history.items()}));
}
},
_default: {
exec: function(cmd, args, callback) {
callback(self.templates.bad_command({cmd: cmd}));
},
completion: function(cmd, arg, line, callback) {
if(!arg) {
arg = cmd;
}
return callback(self.bestMatch(arg, self.commands()))
}
}
};
var _line = {
text: '',
cursor: 0
};
var _searchMatch = '';
var _view, _panel;
var _promptHandler;
var _initializationHandler;
var _initialized;
// public methods
var self = {
commands: commands,
templates: {
history: _.template("<div><% _.each(items, function(cmd, i) { %><div><%- i %>&nbsp;<%- cmd %></div><% }); %></div>"),
help: _.template("<div><div><strong>Commands:</strong></div><% _.each(commands, function(cmd) { %><div>&nbsp;<%- cmd %></div><% }); %></div>"),
bad_command: _.template('<div><strong>Unrecognized command:&nbsp;</strong><%=cmd%></div>'),
input_cmd: _.template('<div id="<%- id %>"><span class="prompt"></span>&nbsp;<span class="input"><span class="left"/><span class="cursor"/><span class="right"/></span></div>'),
empty_input_cmd: _.template('<div id="<%- id %>"></div>'),
input_search: _.template('<div id="<%- id %>">(reverse-i-search)`<span class="searchterm"></span>\':&nbsp;<span class="input"><span class="left"/><span class="cursor"/><span class="right"/></span></div>'),
suggest: _.template("<div><% _.each(suggestions, function(suggestion) { %><div><%- suggestion %></div><% }); %></div>")
},
isActive: function() {
return _readline.isActive();
},
activate: function() {
if($(id(_shell_view_id)).length == 0) {
_active = false;
return;
}
_readline.activate();
},
deactivate: function() {
_console.log("deactivating");
_active = false;
_readline.deactivate();
},
setCommandHandler: function(cmd, cmdHandler) {
_cmdHandlers[cmd] = cmdHandler;
},
getCommandHandler: function(cmd) {
return _cmdHandlers[cmd];
},
setPrompt: function(prompt) {
_prompt = prompt;
if(!_active) {
return;
}
self.refresh();
},
onEOT: function(completionHandler) {
_readline.onEOT(completionHandler);
},
onCancel: function(completionHandler) {
_readline.onCancel(completionHandler);
},
onInitialize: function(completionHandler) {
_initializationHandler = completionHandler;
},
onActivate: function(completionHandler) {
_activationHandler = completionHandler;
},
onDeactivate: function(completionHandler) {
_deactivationHandler = completionHandler;
},
onNewPrompt: function(completionHandler) {
_promptHandler = completionHandler;
},
render: function() {
var text = _line.text || '';
var cursorIdx = _line.cursor || 0;
if(_searchMatch) {
cursorIdx = _searchMatch.cursoridx || 0;
text = _searchMatch.text || '';
$(id(_input_id) + ' .searchterm').text(_searchMatch.term);
}
var left = _.escape(text.substr(0, cursorIdx)).replace(/ /g, '&nbsp;');
var cursor = text.substr(cursorIdx, 1);
var right = _.escape(text.substr(cursorIdx + 1)).replace(/ /g, '&nbsp;');
$(id(_input_id) + ' .prompt').html(_prompt);
$(id(_input_id) + ' .input .left').html(left);
if(!cursor) {
$(id(_input_id) + ' .input .cursor').html('&nbsp;').css('textDecoration', 'underline');
} else {
$(id(_input_id) + ' .input .cursor').text(cursor).css('textDecoration', 'underline');
}
$(id(_input_id) + ' .input .right').html(right);
_cursor_visible = true;
self.scrollToBottom();
_console.log('rendered "' + text + '" w/ cursor at ' + cursorIdx);
},
refresh: function() {
$(id(_input_id)).replaceWith(self.templates.input_cmd({id:_input_id}));
self.render();
_console.log('refreshed ' + _input_id);
},
println: function(text) {
var lines = text.split(/\n/);
for (var i=0; i<lines.length; i++) {
var line = lines[i];
if (line == "\\n") {
continue;
}
$(id(_input_id)).after(line);
$(id(_input_id) + ' .input .cursor').css('textDecoration', '');
$(id(_input_id)).removeAttr('id');
$(id(_shell_view_id)).append(self.templates.empty_input_cmd({id:_input_id}));
}
},
scrollToBottom: function() {
_panel.animate({scrollTop: _view.height()}, 0);
},
bestMatch: function(partial, possible) {
_console.log("bestMatch on partial '" + partial + "'");
var result = {
completion: null,
suggestions: []
};
if(!possible || possible.length == 0) {
return result;
}
var common = '';
if(!partial) {
if(possible.length == 1) {
result.completion = possible[0];
result.suggestions = possible;
return result;
}
if(!_.every(possible, function(x) {
return possible[0][0] == x[0]
})) {
result.suggestions = possible;
return result;
}
}
for(var i = 0; i < possible.length; i++) {
var option = possible[i];
if(option.slice(0, partial.length) == partial) {
result.suggestions.push(option);
if(!common) {
common = option;
_console.log("initial common:" + common);
} else if(option.slice(0, common.length) != common) {
_console.log("find common stem for '" + common + "' and '" + option + "'");
var j = partial.length;
while(j < common.length && j < option.length) {
if(common[j] != option[j]) {
common = common.substr(0, j);
break;
}
j++;
}
}
}
}
result.completion = common.substr(partial.length);
return result;
}
};
function id(id) {
return "#"+id;
}
function commands() {
return _.chain(_cmdHandlers).keys().filter(function(x) {
return x[0] != "_"
}).value();
}
function blinkCursor() {
if(!_active) {
return;
}
root.setTimeout(function() {
if(!_active) {
return;
}
_cursor_visible = !_cursor_visible;
if(_cursor_visible) {
$(id(_input_id) + ' .input .cursor').css('textDecoration', 'underline');
} else {
$(id(_input_id) + ' .input .cursor').css('textDecoration', '');
}
blinkCursor();
}, _blinktime);
}
function split(str) {
return _.filter(str.split(/\s+/), function(x) {
return x;
});
}
function getHandler(cmd) {
return _cmdHandlers[cmd] || _cmdHandlers._default;
}
function renderOutput(output, callback) {
if(output) {
$(id(_input_id)).after(output);
}
$(id(_input_id) + ' .input .cursor').css('textDecoration', '');
$(id(_input_id)).removeAttr('id');
$(id(_shell_view_id)).append(self.templates.input_cmd({id:_input_id}));
if(_promptHandler) {
return _promptHandler(function(prompt) {
self.setPrompt(prompt);
return callback();
});
}
return callback();
}
function activate() {
_console.log("activating shell");
if(!_view) {
_view = $(id(_shell_view_id));
}
if(!_panel) {
_panel = $(id(_shell_panel_id));
}
if($(id(_input_id)).length == 0) {
_view.append(self.templates.input_cmd({id:_input_id}));
}
self.refresh();
_active = true;
blinkCursor();
if(_promptHandler) {
_promptHandler(function(prompt) {
self.setPrompt(prompt);
})
}
if(_activationHandler) {
_activationHandler();
}
}
// init
_readline.onActivate(function() {
if(!_initialized) {
_initialized = true;
if(_initializationHandler) {
return _initializationHandler(activate);
}
}
return activate();
});
_readline.onDeactivate(function() {
if(_deactivationHandler) {
_deactivationHandler();
}
});
_readline.onChange(function(line) {
_line = line;
self.render();
});
_readline.onClear(function() {
_cmdHandlers.clear.exec(null, null, function() {
renderOutput(null, function() {
});
});
});
_readline.onSearchStart(function() {
$(id(_input_id)).replaceWith(self.templates.input_search({id:_input_id}));
_console.log('started search');
});
_readline.onSearchEnd(function() {
$(id(_input_id)).replaceWith(self.templates.input_cmd({id:_input_id}));
_searchMatch = null;
self.render();
_console.log("ended search");
});
_readline.onSearchChange(function(match) {
_searchMatch = match;
self.render();
});
_readline.onEnter(function(cmdtext, callback) {
_console.log("got command: " + cmdtext);
var result;
try {
result = "<div>" + _action(cmdtext) + "</div>";
} catch (e) {
result = "<div>" + e.stack + "</div>";
}
renderOutput(result, function() {
callback("");
});
});
_readline.onCompletion(function(line, callback) {
if(!line) {
return callback();
}
var text = line.text.substr(0, line.cursor);
var parts = split(text);
var cmd = parts.shift() || '';
var arg = parts.pop() || '';
_console.log("getting completion handler for " + cmd);
var handler = getHandler(cmd);
if(handler != _cmdHandlers._default && cmd && cmd == text) {
_console.log("valid cmd, no args: append space");
// the text to complete is just a valid command, append a space
return callback(' ');
}
if(!handler.completion) {
// handler has no completion function, so we can't complete
return callback();
}
_console.log("calling completion handler for " + cmd);
return handler.completion(cmd, arg, line, function(match) {
_console.log("completion: " + JSON.stringify(match));
if(!match) {
return callback();
}
if(match.suggestions && match.suggestions.length > 1) {
return renderOutput(self.templates.suggest({suggestions: match.suggestions}), function() {
callback(match.completion);
});
}
return callback(match.completion);
});
});
return self;
}
})(this, $, _);
var readline = {};
readline.rlwrap = function(action) {
var history = new Josh.History({ key: 'josh.helloworld'});
var shell = Josh.Shell({history: history,
action: action});
var promptCounter = 0;
shell.onNewPrompt(function(callback) {
promptCounter++;
callback("user>");
});
shell.activate();
// map output/print to josh.js output
readline.println = function () {
shell.println(Array.prototype.slice.call(arguments).join(" "));
};
}

5
js/jq_readline.js Normal file
View File

@ -0,0 +1,5 @@
var readline = {
'readline': function(prompt_str) {
return prompt(prompt_str);
}};

View File

@ -6,11 +6,6 @@ if (typeof module !== 'undefined') {
printer.println = exports.println = function () {
console.log.apply(console, arguments);
};
} else {
var exports = printer;
printer.println = function() {
readline.println.apply(null, arguments); // josh_readline.js
}
}
function _pr_str(obj, print_readably) {

View File

@ -21,14 +21,7 @@ function PRINT(exp) {
var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -41,6 +34,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -25,15 +25,7 @@ var re = function(str) { return EVAL(READ(str), {}); };
var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -46,6 +38,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -62,15 +62,7 @@ repl_env['*'] = function(a,b){return a*b;};
repl_env['/'] = function(a,b){return a/b;};
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -83,6 +75,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -76,15 +76,7 @@ repl_env.set('*', function(a,b){return a*b;});
repl_env.set('/', function(a,b){return a/b;});
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -97,6 +89,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -92,15 +92,7 @@ for (var n in core.ns) { repl_env.set(n, core.ns[n]); }
rep("(def! not (fn* (a) (if a false true)))");
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -113,6 +105,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -103,15 +103,7 @@ for (var n in core.ns) { repl_env.set(n, core.ns[n]); }
rep("(def! not (fn* (a) (if a false true)))");
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -124,6 +116,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -112,15 +112,7 @@ if (typeof process !== 'undefined' && process.argv.length > 2) {
}
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -133,6 +125,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -137,15 +137,7 @@ if (typeof process !== 'undefined' && process.argv.length > 2) {
}
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -158,6 +150,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -163,15 +163,7 @@ if (typeof process !== 'undefined' && process.argv.length > 2) {
}
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -184,6 +176,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -169,15 +169,7 @@ if (typeof process !== 'undefined' && process.argv.length > 2) {
}
// repl loop
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
while (true) {
var line = readline.readline("user> ");
@ -190,6 +182,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

View File

@ -181,17 +181,9 @@ if (typeof process !== 'undefined' && process.argv.length > 2) {
}
// repl loop
rep("(println (str \"Mal [\" *host-language* \"]\"))");
if (typeof require === 'undefined') {
// Asynchronous browser mode
readline.rlwrap(function(line) { return rep(line); },
function(exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) { printer.println(exc.stack); }
else { printer.println(exc); }
});
} else if (require.main === module) {
if (typeof require !== 'undefined' && require.main === module) {
// Synchronous node.js commandline mode
rep("(println (str \"Mal [\" *host-language* \"]\"))");
while (true) {
var line = readline.readline("user> ");
if (line === null) { break; }
@ -203,6 +195,4 @@ if (typeof require === 'undefined') {
else { printer.println(exc); }
}
}
} else {
exports.rep = rep;
}

172
js/web/ansi.css Normal file
View File

@ -0,0 +1,172 @@
.jqconsole-ansi-bold {
font-weight: bold!important;
}
.jqconsole-ansi-lighter {
font-weight: lighter!important;
}
.jqconsole-ansi-italic {
font-style: italic!important;
}
.jqconsole-ansi-underline {
text-decoration: underline!important;
}
@-webkit-keyframes blinker {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
@-moz-keyframes blinker {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
@-ms-keyframes blinker {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
@-o-keyframes blinker {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
.jqconsole-ansi-blink {
-webkit-animation-name: blinker;
-moz-animation-name: blinker;
-ms-animation-name: blinker;
-o-animation-name: blinker;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-ms-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-o-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-moz-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-o-animation-duration: 1s;
-ms-animation-duration: 1s;
}
.jqconsole-ansi-blink-rapid {
-webkit-animation-name: blinker;
-moz-animation-name: blinker;
-ms-animation-name: blinker;
-o-animation-name: blinker;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-ms-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-o-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-moz-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-webkit-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
-ms-animation-duration: 0.5s;
}
.jqconsole-ansi-hidden {
visibility:hidden!important;
}
.jqconsole-ansi-line-through {
text-decoration: line-through;
}
.jqconsole-ansi-fonts-1 {
}
.jqconsole-ansi-fonts-2 {
}
.jqconsole-ansi-fonts-3 {
}
.jqconsole-ansi-fonts-4 {
}
.jqconsole-ansi-fonts-5 {
}
.jqconsole-ansi-fonts-6 {
}
.jqconsole-ansi-fonts-7 {
}
.jqconsole-ansi-fonts-8 {
}
.jqconsole-ansi-fonts-9 {
}
.jqconsole-ansi-fraktur {
}
.jqconsole-ansi-color-black {
color: black!important;
}
.jqconsole-ansi-color-red {
color: red!important;
}
.jqconsole-ansi-color-green {
color: green!important;
}
.jqconsole-ansi-color-yellow {
color: yellow!important;
}
.jqconsole-ansi-color-blue {
color: blue!important;
}
.jqconsole-ansi-color-magenta {
color: magenta!important;
}
.jqconsole-ansi-color-cyan {
color: cyan!important;
}
.jqconsole-ansi-color-white {
color: white!important;
}
.jqconsole-ansi-background-color-black {
background-color: black!important;
}
.jqconsole-ansi-background-color-red {
background-color: red!important;
}
.jqconsole-ansi-background-color-green {
background-color: green!important;
}
.jqconsole-ansi-background-color-yellow {
background-color: yellow!important;
}
.jqconsole-ansi-background-color-blue {
background-color: blue!important;
}
.jqconsole-ansi-background-color-magenta {
background-color: magenta!important;
}
.jqconsole-ansi-background-color-cyan {
background-color: cyan!important;
}
.jqconsole-ansi-background-color-white {
background-color: white!important;
}
.jqconsole-ansi-framed {
border: 1px solid!important;
}
.jqconsole-ansi-overline {
text-decoration: overline!important;
}

55
js/web/console.css Normal file
View File

@ -0,0 +1,55 @@
html, body {
background-color: #333;
color: white;
font-family: monospace;
margin: 0;
padding: 0;
}
#console {
height: 400px;
width: 750px;
position:relative;
background-color: black;
border: 2px solid #CCC;
margin: 0 auto;
margin-top: 50px;
}
.jqconsole {
padding: 10px;
padding-bottom: 10px;
}
.jqconsole-cursor {
background-color: #999;
}
.jqconsole-blurred .jqconsole-cursor {
background-color: #666;
}
.jqconsole-prompt {
color: #0d0;
}
.jqconsole-old-prompt {
color: #0b0;
font-weight: normal;
}
.jqconsole-input {
color: #dd0;
}
.jqconsole-old-input {
color: #bb0;
font-weight: normal;
}
.brace {
color: #00FFFF;
}
.paren {
color: #FF00FF;
}
.bracket {
color: #FFFF00;
}
.dquote {
color: #FF8888;
}
.jqconsole-composition {
background-color: red;
}

1
js/web/jqconsole.min.js vendored Normal file

File diff suppressed because one or more lines are too long

121
mal.html
View File

@ -1,52 +1,81 @@
<!doctype html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Make a Lisp</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
<!--<script>Josh = {Debug: true };</script>-->
<script src="js/josh.js/js/killring.js"></script>
<script src="js/josh.js/js/history.js"></script>
<script src="js/josh.js/js/readline.js"></script>
<script src="js/josh.js/js/shell.js"></script>
<script src="js/josh_readline.js"></script>
<style type="text/css">
#shell-panel {
height: 400px;
width: 100%;
background-color: #002f05;
color: #00fe00;
padding: 20px 20px 20px 20px;
font-family: 'Source Code Pro';
overflow: scroll;
overflow-x: hidden;
overflow-y: scroll;
border: 1px dashed #E6EBE0;
}
<head>
<link rel="stylesheet" href="js/web/ansi.css" type="text/css" media="all" />
<link rel="stylesheet" href="js/web/console.css" type="text/css" media="all" />
</head>
<body>
<div id="console"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/web/jqconsole.min.js"></script>
<script src="js/web/mal.js"></script>
<script>
$(function() {
// Creating the console.
window.jqconsole = $('#console').jqconsole(null, 'user> ');
#shell-cli .prompt {
font-weight: bold;
}</style>
</head>
<body>
<div class="wrapper">
printer.println = function () {
var str = Array.prototype.join.call(arguments, " ")
jqconsole.Write(str + "\n");
}
<section>
<h1>Make a Lisp</h1>
rep("(println (str \"Mal [\" *host-language* \"]\"))");
<div id="shell-panel">
<div>Lisp REPL</div>
<div id="shell-view"></div>
</div>
</section>
</div>
// Abort prompt on Ctrl+C.
jqconsole.RegisterShortcut('C', function() {
jqconsole.AbortPrompt();
handler();
});
// Move to line start Ctrl+A.
jqconsole.RegisterShortcut('A', function() {
jqconsole.MoveToStart();
handler();
});
// Move to line end Ctrl+E.
jqconsole.RegisterShortcut('E', function() {
jqconsole.MoveToEnd();
handler();
});
jqconsole.RegisterMatching('{', '}', 'brace');
jqconsole.RegisterMatching('(', ')', 'paren');
jqconsole.RegisterMatching('[', ']', 'bracket');
jqconsole.RegisterMatching('"', '"', 'dquote');
// Handle a command.
var handler = function(line) {
if (line) {
try {
jqconsole.Write(rep(line) + '\n');
} catch (exc) {
if (exc instanceof reader.BlankException) { return; }
if (exc.stack) {
jqconsole.Write(exc.stack + '\n');
} else {
jqconsole.Write(exc + '\n');
}
}
}
jqconsole.Prompt(true, handler);
/*
jqconsole.Prompt(true, handler, function(command) {
// Continue line if can't compile the command.
try {
Function(command);
} catch (e) {
if (/[\[\{\(]$/.test(command)) {
return 1;
} else {
return 0;
}
}
return false;
});
*/
};
<script src="js/mal_web.js"></script>
</body>
// Initiate the first prompt.
handler();
});
</script>
</body>
</html>