Skip to content

Commit

Permalink
refactor: share code for formatting aligned messages (#10906)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sherratt <[email protected]>
  • Loading branch information
gridbugs authored Sep 12, 2024
1 parent 18b66c5 commit 3b9069f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions otherlibs/stdune/src/user_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,9 @@ let command cmd =
; Pp.verbatim "'"
]
;;

let aligned_message ~left:(left_tag, left_string) ~right =
let open Pp.O in
let left_padded = Printf.sprintf "%12s" left_string in
Pp.tag left_tag (Pp.verbatim left_padded) ++ Pp.char ' ' ++ right
;;
5 changes: 5 additions & 0 deletions otherlibs/stdune/src/user_message.mli
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ val needs_stack_trace : t -> bool

(** Formatting of shell commands *)
val command : string -> Style.t Pp.t

(** A message with a left and right component separated by a
space. The left component is padded to 12 characters so that the space
separating the left and right side of all messages are aligned. *)
val aligned_message : left:Style.t * string -> right:Style.t Pp.t -> Style.t Pp.t
6 changes: 3 additions & 3 deletions src/dune_engine/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ end = struct
;;

let progname_and_purpose ~tag ~prog ~purpose =
let open Pp.O in
let progname = sprintf "%12s" (Fancy.short_prog_name_of_prog prog) in
Pp.tag tag (Pp.verbatim progname) ++ Pp.char ' ' ++ pp_purpose purpose
User_message.aligned_message
~left:(tag, Fancy.short_prog_name_of_prog prog)
~right:(pp_purpose purpose)
;;

let pp_ok = progname_and_purpose ~tag:Ok
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/pkg_build_progress.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end
let format_user_message ~verb ~object_ =
let status_tag = User_message.Style.Success in
User_message.make
[ Pp.concat ~sep:Pp.space [ Pp.tag status_tag (Pp.textf "%12s" verb); object_ ] ]
[ User_message.aligned_message ~left:(status_tag, verb) ~right:object_ ]
;;

module Message = struct
Expand Down

0 comments on commit 3b9069f

Please sign in to comment.