Skip to content

Commit

Permalink
refactor format_content function
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Jun 19, 2024
1 parent 9d4ec51 commit 2be90fe
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/glint/internal/help.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ fn to_spaced_indented_string(

let #(content, wrapped) =
list.fold(data, #([], False), fn(acc, data) {
accumulate_formatted_content(acc, f(data), left_length, config)
let #(left, right) = f(data)
let #(line, wrapped) = format_content(left, right, left_length, config)
#([line, ..acc.0], wrapped || acc.1)
})

let joiner = case wrapped {
Expand All @@ -280,14 +282,12 @@ fn to_spaced_indented_string(
content |> list.sort(string.compare) |> string.join(joiner)
}

fn accumulate_formatted_content(
acc: #(List(String), Bool),
data: #(String, String),
fn format_content(
left: String,
right: String,
left_length: Int,
config: Config,
) {
let #(left, right) = data

) -> #(String, Bool) {
let left_formatted = string.pad_right(left, left_length, " ")

let lines =
Expand All @@ -308,14 +308,11 @@ fn accumulate_formatted_content(
}

#(
[
"\n"
<> string.append(
string.repeat(" ", config.indent_width),
left_formatted <> right_formatted,
),
..acc.0
],
wrapped || acc.1,
"\n"
<> string.append(
string.repeat(" ", config.indent_width),
left_formatted <> right_formatted,
),
wrapped,
)
}

0 comments on commit 2be90fe

Please sign in to comment.