Soulignement d'une location: prevoir le cas ou on affiche plusieurs
warnings pour la meme phrase. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@253 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
5804aafa2c
commit
773f1c8184
|
@ -55,6 +55,7 @@ type terminal_info_status = Unknown | Bad_term | Good_term
|
|||
let status = ref Unknown
|
||||
and num_lines = ref 0
|
||||
and cursor_up = ref ""
|
||||
and cursor_down = ref ""
|
||||
and start_standout = ref ""
|
||||
and end_standout = ref ""
|
||||
|
||||
|
@ -63,6 +64,7 @@ let setup_terminal_info() =
|
|||
Terminfo.setupterm();
|
||||
num_lines := Terminfo.getnum "li";
|
||||
cursor_up := Terminfo.getstr "up";
|
||||
cursor_down := Terminfo.getstr "do";
|
||||
begin try
|
||||
start_standout := Terminfo.getstr "us";
|
||||
end_standout := Terminfo.getstr "ue"
|
||||
|
@ -76,6 +78,8 @@ let setup_terminal_info() =
|
|||
|
||||
(* Print the location using standout mode. *)
|
||||
|
||||
let num_loc_lines = ref 0 (* number of lines already printed after input *)
|
||||
|
||||
let rec highlight_location loc =
|
||||
match !status with
|
||||
Unknown ->
|
||||
|
@ -91,7 +95,7 @@ let rec highlight_location loc =
|
|||
(* Do nothing if the buffer does not contain the whole phrase. *)
|
||||
if pos0 < 0 then false else begin
|
||||
(* Count number of lines in phrase *)
|
||||
let lines = ref 0 in
|
||||
let lines = ref !num_loc_lines in
|
||||
for i = pos0 to String.length lb.lex_buffer - 1 do
|
||||
if lb.lex_buffer.[i] = '\n' then incr lines
|
||||
done;
|
||||
|
@ -113,6 +117,10 @@ let rec highlight_location loc =
|
|||
print_char c;
|
||||
bol := (c = '\n')
|
||||
done;
|
||||
(* Position cursor back to original location *)
|
||||
for i = 1 to !num_loc_lines do
|
||||
Terminfo.puts stdout !cursor_down 1
|
||||
done;
|
||||
true
|
||||
end
|
||||
end
|
||||
|
@ -121,6 +129,9 @@ let rec highlight_location loc =
|
|||
|
||||
open Format
|
||||
|
||||
let reset () =
|
||||
num_loc_lines := 0
|
||||
|
||||
let print loc =
|
||||
if String.length !input_name = 0 then
|
||||
if highlight_location loc then () else begin
|
||||
|
@ -141,4 +152,6 @@ let print loc =
|
|||
|
||||
let print_warning loc msg =
|
||||
print loc;
|
||||
print_string "Warning: "; print_string msg; print_newline()
|
||||
print_string "Warning: "; print_string msg; print_newline();
|
||||
incr num_loc_lines
|
||||
|
||||
|
|
|
@ -25,4 +25,4 @@ val input_lexbuf: Lexing.lexbuf option ref
|
|||
|
||||
val print: t -> unit
|
||||
val print_warning: t -> string -> unit
|
||||
|
||||
val reset: unit -> unit
|
||||
|
|
Loading…
Reference in New Issue