=== modified file 'ppio.ml' --- ppio.ml 2019-04-13 01:47:59 +0000 +++ ppio.ml 2019-04-13 01:27:26 +0000 @@ -63,30 +63,20 @@ let s = {to_print = Buffer.create 80; dm = NoFormat} in let write_out () = if Buffer.length s.to_print > 0 then ( - match s.dm with NoFormat | _ -> - Buffer.add_string s.to_print "\x1b[0m"; + Buffer.add_string s.to_print "\x1b[0m"; Out_channel.output_buffer stderr s.to_print; Out_channel.flush stderr; Buffer.clear s.to_print; s.dm <- NoFormat; ) - and add_char = match colors with - | None -> fun c -> ( - if c >= ' ' && c <= '~' then ( - Buffer.add_char s.to_print c; - ) else ( - bprintf s.to_print "\\x%02x" (Char.to_int c); - ) - ) - | Some {normal; escaped} -> fun c -> ( - if c >= ' ' && c <= '~' then ( - Buffer.add_string s.to_print "\x1b["; - Buffer.add_string s.to_print normal; - Buffer.add_char s.to_print 'm'; - Buffer.add_char s.to_print c; - ) else ( - bprintf s.to_print "\x1b[%sm\\x%02x" escaped (Char.to_int c); - ) + and add_char c = + if c >= ' ' && c <= '~' then ( + Buffer.add_string s.to_print "\x1b["; + Buffer.add_string s.to_print colors.normal; + Buffer.add_char s.to_print 'm'; + Buffer.add_char s.to_print c; + ) else ( + bprintf s.to_print "\x1b[%sm\\x%02x" colors.escaped (Char.to_int c); ) in fun (len:int) (buffer:Bytes.t) -> ( @@ -147,8 +137,9 @@ Lwt_unix.set_blocking ~set_flags:true fd1 false; Unix.close stdin_r; Unix.close stdout_w; - let i_cb = pp_writer hideendl endl (Option.map color (fun cs -> cs.i)) - and o_cb = pp_writer hideendl endl (Option.map color (fun cs -> cs.o)) + let i_cb, o_cb = match color with + | None -> (cb_null, cb_null) + | Some cs -> ((pp_writer hideendl endl cs.i), (pp_writer hideendl endl cs.o)) in Lwt_main.run (Lwt.join [ copy_cb fd0 stdin_w i_cb;