diff --git a/README.md b/README.md index 1f16a36..fa13568 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,11 @@ $ rebar3 as test lfe ltest ## Usage [↟](#table-of-contents) -TBD +Assuming you've following the above steps, start up xrepl with the following: + +``` shell +$ rebar3 lfe xrepl +``` ## License [↟](#table-of-contents) diff --git a/priv/banners/v2.txt b/priv/banners/v2.txt new file mode 100644 index 0000000..9bdea30 --- /dev/null +++ b/priv/banners/v2.txt @@ -0,0 +1,13 @@ +{{dbl}}MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM{{end}} +{{dbl}}MM""MMMMMMMM MM""""""""`M MM""""""""`MM{{end}}{{gry}} dP{{end}} +{{dbl}}MM MMMMMMMM MM mmmmmmmM MM mmmmmmmMM{{end}}{{gry}} 88{{end}} +{{blu}}MM MMMMMMMM M' MMMM M` MMMMM{{end}}{{gry}} dP. .dP 88d888b. .d8888b. 88d888b. 88{{end}} +{{blu}}MM MMMMMMMM MM MMMMMMMM MM MMMMMMMMM{{end}}{{gry}} `8bd8' 88' `88 88ooood8 88' `88 88{{end}} +{{gld}}MM MMMMMMMM MM MMMMMMMM MM MMMMMMMMM{{end}}{{gry}} .d88b. 88 88. ... 88. .88 88{{end}} +{{pnk}}MM M MM MMMMMMMM MM .MM{{end}}{{gry}} dP' `dP dP `88888P' 88Y888P' dP{{end}} +{{red}}MMMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMMM{{end}}{{gry}} 88 {{end}} + {{gry}} dP{{end}} +{{bgn}}xrepl{{end}}: {{grn}}{{xrepl-version}} {{cyn}}http://github.com/lfe/xrepl{{end}} +{{bgn}}LFE{{end}}: {{grn}}{{lfe-version}} {{gld}}Get usage info with {{ylw}}(help){{end}} +{{bgn}}Erlang{{end}}: {{grn}}{{erlang-version}} {{gld}}Exit xrepl with {{ylw}}(quit){{end}} + diff --git a/rebar.config b/rebar.config index 9cf3e2f..796e71b 100644 --- a/rebar.config +++ b/rebar.config @@ -1,8 +1,9 @@ -{erl_opts, [debug_info]}. +{erl_opts, [debug_info, {no_auto_import, [{get,1}]}]}. {deps, [ {lfe, "2.1.3"}, - {erlang_color, "1.0.0"} + {erlang_color, "1.0.0"}, + {bbmustache, "1.12.2"} ]}. {plugins, [ diff --git a/rebar.lock b/rebar.lock index a7c1a5a..61cf9c5 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,11 +1,14 @@ {"1.2.0", -[{<<"erlang_color">>,{pkg,<<"erlang_color">>,<<"1.0.0">>},0}, +[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.12.2">>},0}, + {<<"erlang_color">>,{pkg,<<"erlang_color">>,<<"1.0.0">>},0}, {<<"lfe">>,{pkg,<<"lfe">>,<<"2.1.3">>},0}]}. [ {pkg_hash,[ + {<<"bbmustache">>, <<"0CABDCE0DB9FE6D3318131174B9F2B351328A4C0AFBEB3E6E99BB0E02E9B621D">>}, {<<"erlang_color">>, <<"145FE1D2E65C4516E4F03FEFCA6C2F47EBAD5899D978D70382A5CFE643E4AC9E">>}, {<<"lfe">>, <<"6EFCB2BBC1FFC21DC5D1C092F00EFDB397EAC889474AC5C86EDF78A3557CC730">>}]}, {pkg_hash_ext,[ + {<<"bbmustache">>, <<"688B33A4D5CC2D51F575ADF0B3683FC40A38314A2F150906EDCFC77F5B577B3B">>}, {<<"erlang_color">>, <<"6B17E5E589C8FEF540574C9EA32B67CEC2C8A44283AAFE474D6E5818FB3EE038">>}, {<<"lfe">>, <<"4E4BAD515A169AE418FEB7374EA1C8D741FAEA9D95E266CE343B45BCC377F55B">>}]} ]. diff --git a/src/lfe_xrepl.erl b/src/lfe_xrepl.erl index 19c8ca1..340fb10 100644 --- a/src/lfe_xrepl.erl +++ b/src/lfe_xrepl.erl @@ -24,7 +24,7 @@ %% store the current environment when we 'slurp' a file which we can %% revert back to when we do an 'unslurp'. --module(lfe_shell). +-module(lfe_xrepl). -export([start/0,start/1,server/0,server/1, run_script/2,run_script/3, @@ -42,8 +42,8 @@ -import(orddict, [store/3,find/2]). -import(lists, [reverse/1,foreach/2]). --include("lfe.hrl"). --include("lfe_docs.hrl"). +-include_lib("lfe/src/lfe.hrl"). +-include_lib("lfe/src/lfe_docs.hrl"). %% Coloured strings for the LFE banner, red, green, yellow and blue. -define(RED(Str), "\e[31m" ++ Str ++ "\e[0m"). diff --git a/src/xrepl-vsn.lfe b/src/xrepl-vsn.lfe new file mode 100644 index 0000000..0e72528 --- /dev/null +++ b/src/xrepl-vsn.lfe @@ -0,0 +1,35 @@ +(defmodule xrepl-vsn + (export + (get 0) (get 1) + (all 0))) + +(defun get () + (get 'xrepl)) + +(defun get (app-name) + (application:load app-name) + (case (application:get_key app-name 'vsn) + (`#(ok ,vsn) vsn) + (default default))) + +(defun version-arch () + `#(architecture ,(erlang:system_info 'system_architecture))) + +(defun version+name (app-name) + `#(,app-name ,(get app-name))) + +(defun versions-rebar () + `(,(version+name 'rebar) + ,(version+name 'rebar3_lfe))) + +(defun versions-langs () + `(,(version+name 'lfe) + #(erlang ,(erlang:system_info 'otp_release)) + #(emulator ,(erlang:system_info 'version)) + #(driver ,(erlang:system_info 'driver_version)))) + +(defun all () + (lists:append `((,(version+name 'xrepl)) + ,(versions-langs) + ,(versions-rebar) + (,(version-arch))))) diff --git a/src/xrepl.lfe b/src/xrepl.lfe index 07a3544..683d6c1 100644 --- a/src/xrepl.lfe +++ b/src/xrepl.lfe @@ -74,16 +74,52 @@ `#(ok ,state)) ;;; -------------- -;;; our server API +;;; xrepl API ;;; -------------- -(defun start () - (let ((ok (io:put_chars (erlang:whereis 'user) - "YAAAAAAAAAAAAAAAAAYYYYYYYYYYYYYYY!!!!!\n\n")))) - (lfe_shell:start)) +(defun default-opts () + `#m(banner? true)) + +(defun start() + (start #m())) + +(defun start (opts) + (let* ((opts (maps:merge (default-opts) opts)) + (banner? (mref opts 'banner?))) + (if banner? (write (banner))) + (lfe_xrepl:start))) (defun pid () (erlang:whereis (SERVER))) (defun echo (msg) (gen_server:call (SERVER) `#(echo ,msg))) + +;;; Public utility functions + +(defun banner () + (let* ((file (filename:join (list (code:priv_dir 'xrepl) + "banners" + "v2.txt"))) + (`#(ok ,bytes) (file:read_file file))) + (bbmustache:render bytes `#m("xrepl-version" ,(xrepl-vsn:get) + "lfe-version" ,(xrepl-vsn:get 'lfe) + "erlang-version" ,(erlang:system_info 'otp_release) + "red" "\e[31m" + "pnk" "\e[1;31m" + "ylw" "\e[1;33m" + "gld" "\e[33m" + "cyn" "\e[36m" + "blu" "\e[1;34m" + "dbl" "\e[34m" + "grn" "\e[32m" + "bgn" "\e[1;32m" + "gry" "\e[37m" + "end" "\e[0m")))) + +(defun version () (xrepl-vsn:get)) + +(defun versions () (xrepl-vsn:all)) + +(defun write (string) + (io:put_chars (erlang:whereis 'user) string)) \ No newline at end of file