2
Copyright (C) 2007-2009 Stéphane Gimenez
2
Copyright (C) 2007-2010 Stéphane Gimenez
3
3
You have permission to copy, modify, and redistribute under the
4
4
terms of the GPL-3.0. For full license terms, see gpl-3.0.txt.
13
13
Conf.void (F.x "theme" [])
15
let texts : (string * string, (string * F.t) list -> F.t) Hashtbl.t =
15
let texts : (string * string, string * ((string * F.t) list -> F.t)) Hashtbl.t =
16
16
Hashtbl.create 1024
19
19
begin try Some (Sys.getenv "TERM") with Not_found -> None end
21
let escape c = "\027[" ^ c ^ "m", "\027[0m"
22
begin match env_term with
23
| Some ("xterm" | "xterm-color"
24
| "rxvt-256color" | "rxvt-unicode" | "rxvt") ->
25
(fun c -> "\027[" ^ c ^ "m", "\027[0m")
26
| _ -> (fun _ -> "", "")
23
29
let color, bcolor =
24
30
begin match env_term with
94
100
F.h [tag_msg_bad (F.s "<!>"); F.s (snd key); F.v (List.map arg vars)]
96
let def_text key str =
97
let str = str ^ "\n" in
98
let state = ref `Elem in
102
let push c str = str := !str ^ String.make 1 c in
105
if !elem <> "" then l := !l @ [ `Elem !elem ]; elem := ""
107
let add_arg () = l := !l @ [ `Arg !arg ]; arg := "" in
108
let eos = String.length str in
109
while !p < eos do state :=
110
begin match !state, str.[!p] with
111
| `Elem, '<' -> incr p; add_elem (); `Arg
112
| `Elem, '\n' -> incr p; add_elem (); `Elem
113
| `Elem, c -> push c elem; incr p; `Elem
114
| `Arg, '>' -> incr p; add_arg (); `Elem
115
| `Arg, '\n' -> `Error
116
| `Arg, c -> push c arg; incr p; `Arg
117
| `Error, _ -> p := eos; `Error
121
begin match !state with
102
let list_of_string s =
104
if x < 0 then l else aux (x - 1) s (s.[x] :: l)
106
aux (String.length s - 1) s []
108
let get_text_locale key =
109
try fst (Hashtbl.find texts key) with Not_found -> ""
111
let def_text key (locale, str) =
112
let b = Buffer.create 256 in
113
let push c = Buffer.add_char b c in
114
let take () = let c = Buffer.contents b in Buffer.clear b; c in
115
let rec elem stream out =
116
begin match stream with
119
begin match take () with
121
| s -> arg q (`Elem s :: out)
123
| '\n' :: q -> `Error
124
| c :: q -> push c; elem q out
127
begin match take () with
129
| s -> `Elem s :: out
134
begin match stream with
136
begin match take () with
138
| s -> elem q (`Arg s :: out)
141
| '\n' :: q -> `Error
142
| c :: q -> push c; arg q out
146
begin match elem (list_of_string str) [] with
133
F.h ~sep:F.n (List.map map list)
158
F.b (List.map map list)
135
Hashtbl.add texts key msg
160
Hashtbl.add texts key (locale, msg)
137
Hashtbl.add texts key (bad key)
162
Hashtbl.add texts key (locale, bad key)
141
165
let string format t =
191
215
let key = (special, mstr) in
194
begin try (Hashtbl.find texts key) vars with
218
begin try (snd (Hashtbl.find texts key)) vars with
197
(Hashtbl.find texts key) vars
220
def_text key ("", mstr);
221
(snd (Hashtbl.find texts key)) vars
200
224
| Not_found -> bad key vars
215
239
date.Unix.tm_hour date.Unix.tm_min date.Unix.tm_sec
219
add state (Printexc.to_string e)
244
then add state (Printexc.to_string e)
247
F.v (List.map F.s (Str.split (Str.regexp_string "\n") bt))
249
str (F.h [F.s (Printexc.to_string e); fbt]) state
221
251
str (fn ()) state
222
252
| _ -> add state "<unknown>"