Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Erlang and Clojerl version used #24

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions priv/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ var Connection = function(url) {
};
};

var maybeCall = function(value, f) {
value && value.trim() != "" && f(value);
};

var init = function() {
var self = this;
self._conn = new Connection(URL);
self._term = $('#terminal').console({
welcomeMessage:'Welcome to Try Clojerl!',
welcomeMessage: 'Welcome to Try Clojerl!',
promptLabel: 'clje.user=> ',
commandValidate: function(command) {
return true;
Expand Down Expand Up @@ -61,6 +57,7 @@ var init = function() {

self.print = function(json) {
self._term.promptLabel = json.prompt;
self._term.report(json.message, 'stdout');

if(json.result || json.stdout || json.stderr) {
msgs = [ {msg: json.stdout, className: 'stdout'},
Expand Down
28 changes: 16 additions & 12 deletions src/try_clojerl/repl.clje
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
#erl[:cowboy_websocket req state opts]))

(defn websocket_init [state]
(ns clje.user)
#erl[:reply (build-reply) state])
(ns clje.user
(:require [clojure.repl :refer (source apropos dir pst doc find-doc)]
[clojure.pprint :refer (pp pprint)]))
(let [erlang-version (-> :system_version
erlang/system_info.e
erlang/list_to_binary.e)
message (str erlang-version (clojure-version))
reply (build-reply :message message)]
#erl[:reply reply state]))

(defn* websocket_handle [#erl[:text data] state]
(let* [json (jsx/decode.e data #erl(:return_maps))
#erl[res out err] (eval-string (get json "cmd"))
out-frame (build-reply res out err)]
out-frame (build-reply :result res
:stdout out
:stderr err)]
#erl[:reply out-frame state]))

(defn websocket_info [_info state]
Expand All @@ -35,12 +44,7 @@
(defn prompt [] (str *ns* "=> "))

(defn build-reply
([]
#erl[:text
(jsx/encode.e #erl{:prompt (prompt)})])
([res out err]
#erl[:text
(jsx/encode.e #erl{:result res
:stdout out
:stderr err
:prompt (prompt)})]))
[& keyvals]
#erl[:text
(jsx/encode.e (merge #erl{:prompt (prompt)}
(apply hash-map keyvals)))])