Source file chamo_main.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(** Main module of the editor. *)
open Chamo
open Stk.Misc
let _ = Args.parse ()
open Stk.Misc
let () = let> () = Tsdl.Sdl.(init Init.(video+events)) in ()
let () = Lwt_main.run (Stk.App.init
())
let main () =
let logwin = Log.get_log_window () in
Logs.set_reporter (Stk.Textlog.reporter logwin#textlog);
let () =
let json = {|
{ "minibuffer": { inherits: "entry" },
"keystate": { inherits: "label",
bg_color:"blue",
fill: true,
fg_color:"white" },
"minibuffer_vp": {
inherits: "scrollbox",
border_width: 1,
border_color_focused: "green"
}
}
|}
in
let json = Yojson.Safe.from_string json in
Stk.Theme.extend_current_from_json json
in
let waiter, wakener = Lwt.wait () in
Gui.on_last_window_close := (Lwt.wakeup wakener) ;
Lwt.async_exception_hook :=
(fun e -> Log.err (fun m -> m "%s" (Printexc.to_string e)));
List.iter Commands.async_command (!Args.init_commands @ !Args.commands);
View.iter_factories
(fun f -> Misc.catch_print_exceptions (fun () -> f#on_start) ());
begin
try
if Sys.file_exists !Layout.layout_file then
try
let layout = Layout.load_layout !Layout.layout_file in
Layout.create_windows_of_layout layout
with
Failure s
| Sys_error s ->
prerr_endline s;
raise Not_found
else
raise Not_found
with
Not_found ->
match !Gui.gui_windows with
[] -> ignore(Gui.create_window())
| _ -> ()
end;
begin
match !Gui.active_window, !Gui.gui_windows with
None, w :: _ -> Gui.active_window := Some w
| _ -> ()
end;
let on_file file =
Commands.async_launch_command "open_file" [| file |]
in
List.iter on_file !Args.remaining;
let lw = Log.get_log_window () in
lw#window#move ~x: 10 ~y:10;
let%lwt () = Lwt.pick [Stk.App.run(); waiter] in
View.iter_factories
(fun f -> Misc.catch_print_exceptions (fun () -> f#on_exit) ());
Commands.async_command Constant.com_on_exit;
Lwt.return_unit
let () = Lwt_main.run (main ())