diff --git a/src/glint.gleam b/src/glint.gleam index ecb6158..186db46 100644 --- a/src/glint.gleam +++ b/src/glint.gleam @@ -929,43 +929,16 @@ fn flag_help_to_string_with_description( longest_flag_length: Int, config: Config, ) -> #(String, Bool) { - help_content_to_wrapped_string( + utils.help_content_to_wrapped_string( flag_help_to_string(help), help.meta.description, longest_flag_length, - config, + config.min_first_column_width, + config.max_output_width, + config.indent_width, ) } -fn help_content_to_wrapped_string( - left: String, - right: String, - left_length: Int, - config: Config, -) -> #(String, Bool) { - let left_formatted = string.pad_right(left, left_length, " ") - - let right_width = - config.max_output_width - |> int.subtract(left_length + config.indent_width) - |> int.max(config.min_first_column_width) - - let lines = utils.wordwrap(right, right_width) - - let wrapped = case lines { - [] | [_] -> False - _ -> True - } - - let right_formatted = - string.join( - lines, - "\n" <> string.repeat(" ", config.indent_width + left_length), - ) - - #(left_formatted <> right_formatted, wrapped) -} - // -- HELP - FUNCTIONS - STRINGIFIERS - SUBCOMMANDS -- /// generate the styled help text for a list of subcommands @@ -1005,11 +978,13 @@ fn subcommand_help_to_string( longest_subcommand_length: Int, config: Config, ) -> #(String, Bool) { - help_content_to_wrapped_string( + utils.help_content_to_wrapped_string( help.name, help.description, longest_subcommand_length, - config, + config.min_first_column_width, + config.max_output_width, + config.indent_width, ) } diff --git a/src/glint/internal/utils.gleam b/src/glint/internal/utils.gleam index 8b501f3..40cc8e7 100644 --- a/src/glint/internal/utils.gleam +++ b/src/glint/internal/utils.gleam @@ -80,3 +80,31 @@ pub fn to_spaced_indented_string( content |> list.sort(string.compare) |> string.join(joiner) } + +pub fn help_content_to_wrapped_string( + left: String, + right: String, + left_length: Int, + min_left_width: Int, + max_output_width: Int, + indent_width: Int, +) -> #(String, Bool) { + let left_formatted = string.pad_right(left, left_length, " ") + + let right_width = + max_output_width + |> int.subtract(left_length + indent_width) + |> int.max(min_left_width) + + let lines = wordwrap(right, right_width) + + let wrapped = case lines { + [] | [_] -> False + _ -> True + } + + let right_formatted = + string.join(lines, "\n" <> string.repeat(" ", indent_width + left_length)) + + #(left_formatted <> right_formatted, wrapped) +}