open Lwt.Infix open Store module F = Fmt let lang_mime_type = "text/x-ocaml" let lang_name = "ocaml" let use_mime_type = true let font_name = "Monospace 12" let _ = let language_manager = GSourceView3.source_language_manager ~default:true in let lang = if use_mime_type then match language_manager#guess_language ~content_type:lang_mime_type () with | Some x -> x | None -> failwith (sprintf "no language for %s" lang_mime_type) else match language_manager#language lang_name with | Some x -> x | None -> failwith (sprintf "can't load %s" lang_name) in Store.init_default (F.str "%s/console/rootstore.git" Secrets.giturl) >>= fun t -> Store.S.tree t >>= fun rootstore -> (try Store.S.Tree.get rootstore [ ".config"; "init.ml" ] with | Not_found | Invalid_argument _ -> Lwt.return "print_newline \"rootstore://.config/init.ml not found\";;" | exc -> Lwt.return (F.str ".config/init.ml load exception: %s" (Printexc.to_string exc))) >>= fun text -> let source_buffer = GSourceView3.source_buffer ~language:lang ~text ?style_scheme: ((GSourceView3.source_style_scheme_manager ~default:true) #style_scheme "solarized-dark") ~highlight_matching_brackets:true ~highlight_syntax:true () in let win = GWindow.window ~title:"oplevel main" () in let vbox = GPack.vbox ~spacing:10 ~border_width:15 ~packing:win#add () in let scroll_edit = GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC ~packing:vbox#add () in let edit = GSourceView3.source_view ~source_buffer ~auto_indent:true ~insert_spaces_instead_of_tabs:true ~tab_width:2 ~show_line_numbers:true ~right_margin_position:80 ~show_right_margin:true (* ~smart_home_end:true *) ~packing:scroll_edit#add ~height:500 ~width:650 () in edit#misc#modify_font_by_name font_name; edit#set_smart_home_end `AFTER; if edit#smart_home_end <> `AFTER then failwith "regret"; ignore (edit#connect#undo ~callback:(fun _ -> prerr_endline "undo")); let scroll_output = GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC ~packing:vbox#add () in let output_buffer = GText.buffer ~text:"loading..." () in let _output_win = GText.view ~buffer:output_buffer ~editable:false ~cursor_visible:true ~packing:scroll_output#add () in Toploop.initialize_toplevel_env (); let out_ppf = Format.formatter_of_out_functions Format. { out_string = (fun s _ _ -> output_buffer#insert s); out_flush = (fun () -> ()); out_indent = (fun n -> for _ = 0 to n do output_buffer#insert " " done); out_newline = (fun () -> output_buffer#insert "\n"); out_spaces = (fun n -> output_buffer#insert (String.make n ' ')); } in ignore (Toploop.use_input out_ppf (String text))