improvve coloration of program
This commit is contained in:
parent
a3cd58de5d
commit
b3cf69c3d8
|
@ -198,12 +198,39 @@ module Scheduler = struct
|
||||||
| None -> s
|
| None -> s
|
||||||
| Some (s, _) -> s
|
| Some (s, _) -> s
|
||||||
|
|
||||||
|
let colorize_prog s =
|
||||||
|
let len = String.length s in
|
||||||
|
if len = 0 then
|
||||||
|
s
|
||||||
|
else begin
|
||||||
|
let rec find_prog_start i =
|
||||||
|
if i < 0 then
|
||||||
|
0
|
||||||
|
else
|
||||||
|
match s.[i] with
|
||||||
|
| '\\' | '/' -> (i + 1)
|
||||||
|
| _ -> find_prog_start (i - 1)
|
||||||
|
in
|
||||||
|
let prog_end =
|
||||||
|
match s.[len - 1] with
|
||||||
|
| '"' -> len - 1
|
||||||
|
| _ -> len
|
||||||
|
in
|
||||||
|
let prog_start = find_prog_start (prog_end - 1) in
|
||||||
|
let prog_end =
|
||||||
|
match String.index_from s prog_start '.' with
|
||||||
|
| exception _ -> prog_end
|
||||||
|
| i -> i
|
||||||
|
in
|
||||||
|
let before = String.sub s ~pos:0 ~len:prog_start in
|
||||||
|
let after = String.sub s ~pos:prog_end ~len:(len - prog_end) in
|
||||||
|
let key = String.sub s ~pos:prog_start ~len:(prog_end - prog_start) in
|
||||||
|
before ^ Ansi_color.colorize ~key key ^ after
|
||||||
|
end
|
||||||
|
|
||||||
let command_line { prog; args; dir; stdout_to; _ } =
|
let command_line { prog; args; dir; stdout_to; _ } =
|
||||||
let quote = quote_for_shell in
|
let quote = quote_for_shell in
|
||||||
let prog =
|
let prog = colorize_prog (quote prog) in
|
||||||
let s = quote prog in
|
|
||||||
Ansi_color.colorize ~key:(key_for_color prog) s
|
|
||||||
in
|
|
||||||
let s = String.concat (prog :: List.map args ~f:quote) ~sep:" " in
|
let s = String.concat (prog :: List.map args ~f:quote) ~sep:" " in
|
||||||
let s =
|
let s =
|
||||||
match stdout_to with
|
match stdout_to with
|
||||||
|
|
|
@ -349,20 +349,24 @@ end
|
||||||
|
|
||||||
type fail = { fail : 'a. unit -> 'a }
|
type fail = { fail : 'a. unit -> 'a }
|
||||||
|
|
||||||
let quote_for_shell s =
|
let need_quoting s =
|
||||||
let len = String.length s in
|
let len = String.length s in
|
||||||
if len = 0 then
|
len = 0 ||
|
||||||
|
let rec loop i =
|
||||||
|
if i = len then
|
||||||
|
false
|
||||||
|
else
|
||||||
|
match s.[i] with
|
||||||
|
| ' ' | '\"' -> true
|
||||||
|
| _ -> loop (i + 1)
|
||||||
|
in
|
||||||
|
loop 0
|
||||||
|
|
||||||
|
let quote_for_shell s =
|
||||||
|
if need_quoting s then
|
||||||
Filename.quote s
|
Filename.quote s
|
||||||
else
|
else
|
||||||
let rec loop i =
|
s
|
||||||
if i = len then
|
|
||||||
s
|
|
||||||
else
|
|
||||||
match s.[i] with
|
|
||||||
| ' ' | '\"' -> Filename.quote s
|
|
||||||
| _ -> loop (i + 1)
|
|
||||||
in
|
|
||||||
loop 0
|
|
||||||
|
|
||||||
let suggest_function : (string -> string list -> string list) ref = ref (fun _ _ -> [])
|
let suggest_function : (string -> string list -> string list) ref = ref (fun _ _ -> [])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue