diff --git a/CHANGES.md b/CHANGES.md index 51cf3b8f613e..5509205f7d20 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ 3.5.0 (unreleased) ------------------ +- Add a terminal persistence mode that attempts to clear the terminal history. + It is enabled by setting terminal persistence to + `clear-on-rebuild-and-flush-history` (#6065, @rgrinberg) + - Disallow generating targets in sub direcories in inferred rules. The check to forbid this was accidentally done only for manually specified targets (#6031, @rgrinberg) diff --git a/bin/import.ml b/bin/import.ml index c59c6ba219b4..2ae94312de2d 100644 --- a/bin/import.ml +++ b/bin/import.ml @@ -79,6 +79,7 @@ module Scheduler = struct | false -> ( match dune_config.terminal_persistence with | Clear_on_rebuild -> Console.reset () + | Clear_on_rebuild_and_flush_history -> Console.reset_flush_history () | Preserve -> let message = sprintf "********** NEW BUILD (%s) **********" diff --git a/otherlibs/stdune/console.ml b/otherlibs/stdune/console.ml index ddae71a3a335..dd88c8e374e7 100644 --- a/otherlibs/stdune/console.ml +++ b/otherlibs/stdune/console.ml @@ -7,6 +7,8 @@ module Backend = struct val print_if_no_status_line : User_message.Style.t Pp.t -> unit val reset : unit -> unit + + val reset_flush_history : unit -> unit end type t = (module S) @@ -26,6 +28,8 @@ module Backend = struct (Pp.seq (Pp.map_tags msg ~f:User_message.Print_config.default) Pp.cut) let reset () = prerr_string "\x1b[H\x1b[2J" + + let reset_flush_history () = prerr_string "\x1bc" end module Dumb : S = struct @@ -42,6 +46,10 @@ module Backend = struct let reset () = reset (); flush stderr + + let reset_flush_history () = + reset_flush_history (); + flush stderr end module Progress : S = struct @@ -79,6 +87,8 @@ module Backend = struct flush stderr let reset () = Dumb.reset () + + let reset_flush_history () = Dumb.reset_flush_history () end let dumb = (module Dumb : S) @@ -106,6 +116,10 @@ module Backend = struct let reset () = A.reset (); B.reset () + + let reset_flush_history () = + A.reset_flush_history (); + B.reset_flush_history () end : S) end @@ -129,6 +143,10 @@ let reset () = let (module M : Backend.S) = !Backend.main in M.reset () +let reset_flush_history () = + let (module M : Backend.S) = !Backend.main in + M.reset_flush_history () + module Status_line = struct type t = | Live of (unit -> User_message.Style.t Pp.t) diff --git a/otherlibs/stdune/console.mli b/otherlibs/stdune/console.mli index 43d185682673..e6c121959531 100644 --- a/otherlibs/stdune/console.mli +++ b/otherlibs/stdune/console.mli @@ -20,6 +20,8 @@ module Backend : sig (** Reset the log output *) val reset : unit -> unit + + val reset_flush_history : unit -> unit end type t = (module S) diff --git a/src/dune_config/dune_config.ml b/src/dune_config/dune_config.ml index 704dbe102139..e17806794cb6 100644 --- a/src/dune_config/dune_config.ml +++ b/src/dune_config/dune_config.ml @@ -16,15 +16,21 @@ module Terminal_persistence = struct type t = | Preserve | Clear_on_rebuild + | Clear_on_rebuild_and_flush_history - let all = [ ("preserve", Preserve); ("clear-on-rebuild", Clear_on_rebuild) ] + let all = + [ ("preserve", Preserve) + ; ("clear-on-rebuild", Clear_on_rebuild) + ; ("clear-on-rebuild-and-flush-history", Clear_on_rebuild_and_flush_history) + ] let to_dyn = function | Preserve -> Dyn.Variant ("Preserve", []) | Clear_on_rebuild -> Dyn.Variant ("Clear_on_rebuild", []) + | Clear_on_rebuild_and_flush_history -> + Variant ("Clear_on_rebuild_and_flush_history", []) - let decode = - enum [ ("perserve", Preserve); ("clear-on-rebuild", Clear_on_rebuild) ] + let decode = enum all end module Concurrency = struct diff --git a/src/dune_config/dune_config.mli b/src/dune_config/dune_config.mli index 967ae820df93..83c8dad69b64 100644 --- a/src/dune_config/dune_config.mli +++ b/src/dune_config/dune_config.mli @@ -44,6 +44,7 @@ module Terminal_persistence : sig type t = | Preserve | Clear_on_rebuild + | Clear_on_rebuild_and_flush_history val all : (string * t) list end