Compare commits
1 Commits
c065a0423b
...
memes
| Author | SHA1 | Date | |
|---|---|---|---|
| 69cb7dffaf |
188
index.html
188
index.html
@ -1,188 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<title>OCaml toplevel</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
|
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
|
|
||||||
<style>
|
|
||||||
|
|
||||||
code, kbd, pre, samp {
|
|
||||||
font-family: Menlo,Monaco,Consolas,monospace;
|
|
||||||
}
|
|
||||||
body,html {
|
|
||||||
height: 100%;
|
|
||||||
background-color:#eee;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplevel-container {
|
|
||||||
width: 50%;
|
|
||||||
background-color: black;
|
|
||||||
color: #ccc;
|
|
||||||
overflow: auto;
|
|
||||||
overflow-x: hidden;
|
|
||||||
height: 100%;
|
|
||||||
float:left;
|
|
||||||
padding:10px;
|
|
||||||
padding-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplevel-container pre#output {
|
|
||||||
padding: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplevel-container .statusv {
|
|
||||||
background-color:transparent;
|
|
||||||
color: #ccc;
|
|
||||||
border: none;
|
|
||||||
line-height:18px;
|
|
||||||
font-size: 12px;
|
|
||||||
margin-bottom: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplevel-container #output {
|
|
||||||
width:90%;
|
|
||||||
line-height:18px;
|
|
||||||
font-size: 12px;
|
|
||||||
background-color: transparent;
|
|
||||||
color: #fff;
|
|
||||||
border: 0;
|
|
||||||
resize: none;
|
|
||||||
outline: none;
|
|
||||||
font-family: Menlo,Monaco,Consolas,monospace;
|
|
||||||
font-weight: bold;
|
|
||||||
float:left;
|
|
||||||
margin: 0px;
|
|
||||||
padding:0px;
|
|
||||||
}
|
|
||||||
#toplevel-container #sharp {
|
|
||||||
float: left;
|
|
||||||
line-height:18px;
|
|
||||||
font-size: 12px;
|
|
||||||
font-family: Menlo,Monaco,Consolas,monospace;
|
|
||||||
white-space: pre;
|
|
||||||
}
|
|
||||||
.sharp:before{
|
|
||||||
content:"# ";
|
|
||||||
line-height:18px;
|
|
||||||
font-size: 12px;
|
|
||||||
font-family: Menlo,Monaco,Consolas,monospace;
|
|
||||||
}
|
|
||||||
.caml{
|
|
||||||
color:rgb(110, 110, 201);
|
|
||||||
}
|
|
||||||
#toplevel-side{
|
|
||||||
position:relative;
|
|
||||||
width:45%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: auto;
|
|
||||||
text-align:justify;
|
|
||||||
float:left;
|
|
||||||
margin-left:30px;
|
|
||||||
}
|
|
||||||
#toplevel-side ul{
|
|
||||||
padding: 0px;
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stderr {
|
|
||||||
color: #d9534f;
|
|
||||||
}
|
|
||||||
.stdout {
|
|
||||||
|
|
||||||
}
|
|
||||||
.errorloc{
|
|
||||||
border-bottom-width: 3px;
|
|
||||||
border-bottom-style: solid;
|
|
||||||
border-bottom-color: red;
|
|
||||||
}
|
|
||||||
canvas {
|
|
||||||
border: 1px dashed black;
|
|
||||||
float: left;
|
|
||||||
margin: 7px;
|
|
||||||
}
|
|
||||||
#output canvas {
|
|
||||||
background-color: #464646;
|
|
||||||
float: none;
|
|
||||||
display: block;
|
|
||||||
border: 1px dashed while;
|
|
||||||
margin: 7px;
|
|
||||||
}
|
|
||||||
#output img {
|
|
||||||
display:block;
|
|
||||||
}
|
|
||||||
#toplevel-examples {
|
|
||||||
width: 270px;
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
#toplevel-examples .list-group-item{
|
|
||||||
padding: 5px 15px;
|
|
||||||
}
|
|
||||||
#btn-share {
|
|
||||||
float:right;
|
|
||||||
margin-top:-20px;
|
|
||||||
background-color:rgb(92, 129, 184);
|
|
||||||
border-color: rgb(70, 75, 128);
|
|
||||||
padding: 1px 5px;
|
|
||||||
display:none;
|
|
||||||
}
|
|
||||||
.clear { clear:both; }
|
|
||||||
|
|
||||||
.sharp .id { color: #59B65C ; font-style: italic }
|
|
||||||
.sharp .kw0 { color: rgb(64, 75, 190); font-weight: bold ;}
|
|
||||||
.sharp .kw1 { color: rgb(150, 0, 108); font-weight: bold ;}
|
|
||||||
.sharp .kw2 { color: rgb(23, 100, 42); font-weight: bold ;}
|
|
||||||
.sharp .kw3 { color: #59B65C; font-weight: bold ;}
|
|
||||||
.sharp .kw4 { color: #59B65C; font-weight: bold ;}
|
|
||||||
.sharp .comment { color: green ; font-style: italic ; }
|
|
||||||
.sharp .string { color: #6B6B6B; font-weight: bold ; }
|
|
||||||
.sharp .text { }
|
|
||||||
.sharp .numeric { color: #729AAF; }
|
|
||||||
.sharp .directive { font-style: italic ; color : #EB00FF; } ;
|
|
||||||
.sharp .escape { color: #409290 ; }
|
|
||||||
.sharp .symbol0 { color: orange ; font-weight: bold ; }
|
|
||||||
.sharp .symbol1 { color: #993300 ; font-weight: bold ; }
|
|
||||||
.sharp .constant { color: rgb(0, 152, 255); }
|
|
||||||
</style>
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
window.onhashchange = function() { window.location.reload() }
|
|
||||||
var hash = window.location.hash.replace(/^#/,"");
|
|
||||||
var fields = hash.split(/&/);
|
|
||||||
var prefix = "";
|
|
||||||
var version = "";
|
|
||||||
var main = "oplevel.bc.js";
|
|
||||||
function load_script(url){
|
|
||||||
var fileref=document.createElement('script');
|
|
||||||
fileref.setAttribute("type","text/javascript");
|
|
||||||
fileref.setAttribute("src", prefix+(version==""?"":(version+"/"))+url);
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(fileref);
|
|
||||||
}
|
|
||||||
load_script("exported-unit.cmis.js");
|
|
||||||
load_script(main);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="toplevel-container">
|
|
||||||
<pre id="output"></pre>
|
|
||||||
<div>
|
|
||||||
<div id="sharp" class="sharp"></div>
|
|
||||||
<textarea id="userinput">Loading ...</textarea>
|
|
||||||
<button type="button" class="btn btn-default"
|
|
||||||
id="btn-share">Share</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="toplevel-side">
|
|
||||||
<h3>OpLevel</h3>
|
|
||||||
<h4>A programming system based on a compiler from OCaml bytecode to Javascript.</h4>
|
|
||||||
<div id="toplevel-storeview" class="list-group"></div>
|
|
||||||
<canvas width=200 height=200 id="test-canvas"></canvas>
|
|
||||||
<h4 class="clear">See the generated javascript code</h4>
|
|
||||||
<pre id="last-js">
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -15,7 +15,7 @@ let resize ~container ~textbox () =
|
|||||||
textbox##.style##.height := Js.string "auto";
|
textbox##.style##.height := Js.string "auto";
|
||||||
textbox##.style##.height
|
textbox##.style##.height
|
||||||
:= Js.string (Printf.sprintf "%dpx" (max 18 textbox##.scrollHeight));
|
:= Js.string (Printf.sprintf "%dpx" (max 18 textbox##.scrollHeight));
|
||||||
container##.scrollTop := container##.scrollHeight;
|
(* container##.scrollTop := container##.scrollHeight; *)
|
||||||
Lwt.return ()
|
Lwt.return ()
|
||||||
|
|
||||||
let appendchild ~container html =
|
let appendchild ~container html =
|
||||||
@ -37,7 +37,7 @@ let _ =
|
|||||||
[ txt "starting..." ];
|
[ txt "starting..." ];
|
||||||
]);
|
]);
|
||||||
let textbox : 'a Js.t =
|
let textbox : 'a Js.t =
|
||||||
by_id_coerce "userinput" Dom_html.CoerceTo.textarea
|
by_id_coerce "code" Dom_html.CoerceTo.textarea
|
||||||
in
|
in
|
||||||
let rootrepo = Store.test_pull () in
|
let rootrepo = Store.test_pull () in
|
||||||
rootrepo >>= fun (_upstream, t) ->
|
rootrepo >>= fun (_upstream, t) ->
|
||||||
@ -65,11 +65,11 @@ let _ =
|
|||||||
(* setup handlers *)
|
(* setup handlers *)
|
||||||
textbox##.onkeyup :=
|
textbox##.onkeyup :=
|
||||||
Dom_html.handler (fun _ ->
|
Dom_html.handler (fun _ ->
|
||||||
Lwt.async (resize ~container ~textbox);
|
(* Lwt.async (resize ~container ~textbox); *)
|
||||||
Js._true);
|
Js._true);
|
||||||
textbox##.onchange :=
|
textbox##.onchange :=
|
||||||
Dom_html.handler (fun _ ->
|
Dom_html.handler (fun _ ->
|
||||||
Lwt.async (resize ~container ~textbox);
|
(* Lwt.async (resize ~container ~textbox); *)
|
||||||
Js._true);
|
Js._true);
|
||||||
textbox##.onkeydown :=
|
textbox##.onkeydown :=
|
||||||
Dom_html.handler
|
Dom_html.handler
|
||||||
|
|||||||
75
toplevel.ml
75
toplevel.ml
@ -225,75 +225,13 @@ let rec iter_on_sharp ~f x =
|
|||||||
| None -> ()
|
| None -> ()
|
||||||
| Some n -> iter_on_sharp ~f n
|
| Some n -> iter_on_sharp ~f n
|
||||||
|
|
||||||
let setup_share_button ~output =
|
let setup_run_button ~execute =
|
||||||
do_by_id "btn-share" (fun e ->
|
do_by_id "btn-run" (fun e ->
|
||||||
e##.style##.display := Js.string "block";
|
e##.style##.display := Js.string "block";
|
||||||
e##.onclick :=
|
e##.onclick :=
|
||||||
Dom_html.handler (fun _ ->
|
Dom_html.handler (fun _ ->
|
||||||
(* get all ocaml code *)
|
let textbox = by_id "code" in
|
||||||
let code = ref [] in
|
execute (Js.to_string textbox##.innerText##trim);
|
||||||
Js.Opt.iter output##.firstChild
|
|
||||||
(iter_on_sharp ~f:(fun e ->
|
|
||||||
code :=
|
|
||||||
Js.Opt.case e##.textContent
|
|
||||||
(fun () -> "")
|
|
||||||
Js.to_string
|
|
||||||
:: !code));
|
|
||||||
let code_encoded =
|
|
||||||
B64.encode (String.concat "" (List.rev !code))
|
|
||||||
in
|
|
||||||
let url, is_file =
|
|
||||||
match Url.Current.get () with
|
|
||||||
| Some (Url.Http url) ->
|
|
||||||
(Url.Http { url with Url.hu_fragment = "" }, false)
|
|
||||||
| Some (Url.Https url) ->
|
|
||||||
(Url.Https { url with Url.hu_fragment = "" }, false)
|
|
||||||
| Some (Url.File url) ->
|
|
||||||
(Url.File { url with Url.fu_fragment = "" }, true)
|
|
||||||
| _ -> assert false
|
|
||||||
in
|
|
||||||
let frag =
|
|
||||||
let frags = parse_hash () in
|
|
||||||
let frags =
|
|
||||||
List.remove_assoc "code" frags
|
|
||||||
@ [ ("code", code_encoded) ]
|
|
||||||
in
|
|
||||||
Url.encode_arguments frags
|
|
||||||
in
|
|
||||||
let uri = Url.string_of_url url ^ "#" ^ frag in
|
|
||||||
let append_url str =
|
|
||||||
let dom =
|
|
||||||
Tyxml_js.Html.(
|
|
||||||
p
|
|
||||||
[
|
|
||||||
txt "Share this url : ";
|
|
||||||
a ~a:[ a_href str ] [ txt str ];
|
|
||||||
])
|
|
||||||
in
|
|
||||||
Dom.appendChild output (Tyxml_js.To_dom.of_element dom)
|
|
||||||
in
|
|
||||||
Lwt.async (fun () ->
|
|
||||||
Lwt.catch
|
|
||||||
(fun () ->
|
|
||||||
if is_file then
|
|
||||||
failwith "Cannot shorten url with file scheme"
|
|
||||||
else
|
|
||||||
let uri =
|
|
||||||
Printf.sprintf
|
|
||||||
"http://is.gd/create.php?format=json&url=%s"
|
|
||||||
(Url.urlencode uri)
|
|
||||||
in
|
|
||||||
Lwt.bind (Js_of_ocaml_lwt.Jsonp.call uri)
|
|
||||||
(fun o ->
|
|
||||||
let str = Js.to_string o##.shorturl in
|
|
||||||
append_url str;
|
|
||||||
Lwt.return_unit))
|
|
||||||
(fun exn ->
|
|
||||||
Format.eprintf
|
|
||||||
"Could not generate short url. reason: %s@."
|
|
||||||
(Printexc.to_string exn);
|
|
||||||
append_url uri;
|
|
||||||
Lwt.return_unit));
|
|
||||||
Js._false))
|
Js._false))
|
||||||
|
|
||||||
let setup_js_preview () =
|
let setup_js_preview () =
|
||||||
@ -383,7 +321,7 @@ let run ~init ~output () :
|
|||||||
|
|
||||||
let container = by_id "toplevel-container" in
|
let container = by_id "toplevel-container" in
|
||||||
let textbox : 'a Js.t =
|
let textbox : 'a Js.t =
|
||||||
by_id_coerce "userinput" Dom_html.CoerceTo.textarea
|
by_id_coerce "code" Dom_html.CoerceTo.textarea
|
||||||
in
|
in
|
||||||
let sharp_chan = open_out "/dev/null0" in
|
let sharp_chan = open_out "/dev/null0" in
|
||||||
let sharp_ppf = Format.formatter_of_out_channel sharp_chan in
|
let sharp_ppf = Format.formatter_of_out_channel sharp_chan in
|
||||||
@ -402,7 +340,6 @@ let run ~init ~output () :
|
|||||||
else content
|
else content
|
||||||
in
|
in
|
||||||
current_position := output##.childNodes##.length;
|
current_position := output##.childNodes##.length;
|
||||||
textbox##.value := Js.string "";
|
|
||||||
History.push content;
|
History.push content;
|
||||||
JsooTop.execute true ~pp_code ~highlight_location caml_ppf
|
JsooTop.execute true ~pp_code ~highlight_location caml_ppf
|
||||||
content';
|
content';
|
||||||
@ -443,7 +380,7 @@ let run ~init ~output () :
|
|||||||
(fun s -> Js.to_string s ^ "\n")
|
(fun s -> Js.to_string s ^ "\n")
|
||||||
in
|
in
|
||||||
Sys_js.set_channel_filler stdin readline;
|
Sys_js.set_channel_filler stdin readline;
|
||||||
setup_share_button ~output;
|
setup_run_button ~execute;
|
||||||
(* setup_examples ~container ~textbox; *)
|
(* setup_examples ~container ~textbox; *)
|
||||||
setup_pseudo_fs ~load_cmis_from_server:false;
|
setup_pseudo_fs ~load_cmis_from_server:false;
|
||||||
setup_toplevel ();
|
setup_toplevel ();
|
||||||
|
|||||||
Reference in New Issue
Block a user