···8 | Format of id * string
9 | Setup
1011-type output = Stdout of string | Stderr of string | Meta of string
00001213type response =
14 | Merlin_response of id * Merlin_protocol.answer
···8 | Format of id * string
9 | Setup
1011+type output =
12+ | Stdout of string
13+ | Stderr of string
14+ | Meta of string
15+ | Html of string
1617type response =
18 | Merlin_response of id * Merlin_protocol.answer
+11-6
src/cell.ml
···158 refresh_lines_from ~editor
159160let render_message msg =
000000161 let kind, text =
162 match msg with
163- | X_protocol.Stdout str -> ("stdout", str)
164- | Stderr str -> ("stderr", str)
165- | Meta str -> ("meta", str)
0166 in
167- El.pre
168- ~at:[ At.class' (Jstr.of_string ("caml_" ^ kind)) ]
169- [ El.txt (Jstr.of_string text) ]
170171let add_message t loc msg =
172 Editor.add_message t.cm loc (List.map render_message msg)
···158 refresh_lines_from ~editor
159160let 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 ]
00175176let add_message t loc msg =
177 Editor.add_message t.cm loc (List.map render_message msg)
+1-2
src/editor.ml
···39let 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
4445let custom_ln editor =
46 Code_mirror.Editor.View.line_numbers (fun x ->
···39let refresh_messages ed =
40 Code_mirror.Editor.View.dispatch ed.view
41 (Code_mirror.Compartment.reconfigure ed.messages_comp
42+ [ render_messages ed ])
04344let custom_ln editor =
45 Code_mirror.Editor.View.line_numbers (fun x ->
···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
···00000
···1+val output_html : string -> unit
2+3+(**/**)
4+5+val id : (int * int) ref
···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
092 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