this repo has no description

add X_ocaml_lib.output_html

ArthurW 889cd800 09ae6b5a

+57 -21
+1 -1
bin/x_ocaml.ml
··· 152 | [] -> targets 153 | _ -> targets @ ppxs @ [ "ppxlib_register" ] 154 in 155 - let env = Env.empty in 156 let env, all_ppxs = dependencies ~ppx:true ppxs env in 157 let _env, all_libs = dependencies ~ppx:false targets env in 158 let all = all_ppxs @ all_libs in
··· 152 | [] -> targets 153 | _ -> targets @ ppxs @ [ "ppxlib_register" ] 154 in 155 + let env = Env.singleton "x-ocaml.lib" in 156 let env, all_ppxs = dependencies ~ppx:true ppxs env in 157 let _env, all_libs = dependencies ~ppx:false targets env in 158 let all = all_ppxs @ all_libs in
+1
protocol/dune
··· 1 (library 2 (name x_protocol) 3 (libraries merlin-js.protocol))
··· 1 (library 2 + (public_name x-ocaml.protocol) 3 (name x_protocol) 4 (libraries merlin-js.protocol))
+5 -1
protocol/x_protocol.ml
··· 8 | Format of id * string 9 | Setup 10 11 - type output = Stdout of string | Stderr of string | Meta of string 12 13 type response = 14 | Merlin_response of id * Merlin_protocol.answer
··· 8 | Format of id * string 9 | Setup 10 11 + type output = 12 + | Stdout of string 13 + | Stderr of string 14 + | Meta of string 15 + | Html of string 16 17 type response = 18 | Merlin_response of id * Merlin_protocol.answer
+11 -6
src/cell.ml
··· 158 refresh_lines_from ~editor 159 160 let render_message msg = 161 let kind, text = 162 match msg with 163 - | X_protocol.Stdout str -> ("stdout", str) 164 - | Stderr str -> ("stderr", str) 165 - | Meta str -> ("meta", str) 166 in 167 - El.pre 168 - ~at:[ At.class' (Jstr.of_string ("caml_" ^ kind)) ] 169 - [ El.txt (Jstr.of_string text) ] 170 171 let add_message t loc msg = 172 Editor.add_message t.cm loc (List.map render_message msg)
··· 158 refresh_lines_from ~editor 159 160 let render_message msg = 161 + let raw_html s = 162 + let el = El.div [] in 163 + let el_t = El.to_jv el in 164 + Jv.set el_t "innerHTML" (Jv.of_jstr @@ Jstr.of_string s); 165 + el 166 + in 167 let kind, text = 168 match msg with 169 + | X_protocol.Stdout str -> ("stdout", El.txt' str) 170 + | Stderr str -> ("stderr", El.txt' str) 171 + | Meta str -> ("meta", El.txt' str) 172 + | Html str -> ("html", raw_html str) 173 in 174 + El.pre ~at:[ At.class' (Jstr.of_string ("caml_" ^ kind)) ] [ text ] 175 176 let add_message t loc msg = 177 Editor.add_message t.cm loc (List.map render_message msg)
+1 -2
src/editor.ml
··· 39 let refresh_messages ed = 40 Code_mirror.Editor.View.dispatch ed.view 41 (Code_mirror.Compartment.reconfigure ed.messages_comp 42 - [ render_messages ed ]); 43 - Code_mirror.Editor.View.request_measure ed.view 44 45 let custom_ln editor = 46 Code_mirror.Editor.View.line_numbers (fun x ->
··· 39 let refresh_messages ed = 40 Code_mirror.Editor.View.dispatch ed.view 41 (Code_mirror.Compartment.reconfigure ed.messages_comp 42 + [ render_messages ed ]) 43 44 let custom_ln editor = 45 Code_mirror.Editor.View.line_numbers (fun x ->
+13
src/style.css
··· 74 padding-bottom: 0.5em; 75 background: #eee; 76 }
··· 74 padding-bottom: 0.5em; 75 background: #eee; 76 } 77 + .caml_html { 78 + margin: 0; 79 + padding: 0.2em 0.5em; 80 + color: black; 81 + border: 1px solid transparent; 82 + white-space: collapse; 83 + } 84 + 85 + table, tr, td, th { 86 + border: 1px solid black; 87 + border-collapse: collapse; 88 + padding: 0.2em; 89 + }
+4
worker-lib/dune
···
··· 1 + (library 2 + (public_name x-ocaml.lib) 3 + (name x_ocaml_lib) 4 + (libraries x-ocaml.protocol js_of_ocaml))
+8
worker-lib/x_ocaml_lib.ml
···
··· 1 + let id = ref (0, 0) 2 + 3 + let output_html m = 4 + let id, loc = !id in 5 + Js_of_ocaml.Worker.post_message 6 + (X_protocol.resp_to_bytes 7 + (X_protocol.Top_response_at (id, loc, [ Html m ]))); 8 + ()
+5
worker-lib/x_ocaml_lib.mli
···
··· 1 + val output_html : string -> unit 2 + 3 + (**/**) 4 + 5 + val id : (int * int) ref
+6 -10
worker/dune
··· 1 (library 2 (name x_worker) 3 - (libraries 4 - brr 5 - js_of_ocaml 6 - js_of_ocaml-toplevel 7 - x_protocol 8 - merlin-js.worker 9 - ocamlformat-lib 10 - ocamlformat-lib.parser_extended 11 ocamlformat-lib.format_)) 12 13 (rule ··· 18 %{targets} 19 (progn 20 (cat %{deps}) 21 - (echo "Ast_mapper\n"))))) 22 23 (rule 24 (target export-stdlib.txt) 25 (action 26 - (run jsoo_listunits -o %{target} stdlib)))
··· 1 (library 2 (name x_worker) 3 + (libraries brr js_of_ocaml js_of_ocaml-toplevel x-ocaml.protocol x-ocaml.lib 4 + merlin-js.worker ocamlformat-lib ocamlformat-lib.parser_extended 5 ocamlformat-lib.format_)) 6 7 (rule ··· 12 %{targets} 13 (progn 14 (cat %{deps}) 15 + (echo "Ast_mapper\n") 16 + (echo "X_ocaml_lib\n"))))) 17 18 (rule 19 (target export-stdlib.txt) 20 (action 21 + (run jsoo_listunits -o %{target} stdlib 22 + %{dep:../worker-lib/x_ocaml_lib.cma})))
+2 -1
worker/eval.ml
··· 67 List.rev out 68 in 69 let respond ~(at_loc : Location.t) = 70 - let loc = at_loc.loc_end.pos_cnum - line_number in 71 let out = get_out () in 72 output ~loc out 73 in ··· 89 | Ptop_dir { pdir_loc = loc; _ } -> loc 90 | _ -> assert false 91 in 92 try 93 Location.reset (); 94 let phrase = preprocess_phrase phrase in
··· 67 List.rev out 68 in 69 let respond ~(at_loc : Location.t) = 70 + let loc = at_loc.loc_end.pos_cnum in 71 let out = get_out () in 72 output ~loc out 73 in ··· 89 | Ptop_dir { pdir_loc = loc; _ } -> loc 90 | _ -> assert false 91 in 92 + X_ocaml_lib.id := (id, at_loc.loc_end.pos_cnum); 93 try 94 Location.reset (); 95 let phrase = preprocess_phrase phrase in