MCPcopy Index your code
hub / github.com/endbasic/endbasic / refill_many

Function refill_many

std/src/console/format.rs:65–103  ·  view source on GitHub ↗

Refills a collection of paragraphs, prefixing them with an optional `indent`.

(
    paragraphs: P,
    indent: &str,
    width: usize,
)

Source from the content-addressed store, hash-verified

63
64/// Refills a collection of paragraphs, prefixing them with an optional `indent`.
65fn refill_many<S: AsRef<str>, P: IntoIterator<Item = S>>(
66 paragraphs: P,
67 indent: &str,
68 width: usize,
69) -> Vec<String> {
70 let mut formatted = vec![];
71
72 let mut first = true;
73 for paragraph in paragraphs {
74 let paragraph = paragraph.as_ref();
75
76 if !first {
77 formatted.push(String::new());
78 }
79 first = false;
80
81 let mut extra_indent = String::new();
82 for ch in paragraph.chars() {
83 // TODO(jmmv): It'd be nice to recognize '*' prefixes so that continuation lines in
84 // lists look nicer.
85 if ch.is_whitespace() {
86 extra_indent.push(' ');
87 } else {
88 break;
89 }
90 }
91
92 let lines = refill(paragraph, width - 4 - indent.len() - extra_indent.len());
93 for line in lines {
94 if line.is_empty() {
95 formatted.push(String::new());
96 } else {
97 formatted.push(format!("{}{}{}", indent, extra_indent, line));
98 }
99 }
100 }
101
102 formatted
103}
104
105/// Same as `refill` but prints the lines of each paragraph to the console instead of returning
106/// them and prefixes them with an optional `indent`.

Callers 2

refill_and_printFunction · 0.85
refill_and_pageFunction · 0.85

Calls 5

refillFunction · 0.85
pushMethod · 0.80
charsMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected