You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, one may want to find the smallest width such that any wrapped line won't protrude out, without the need to actually wrap the text into string.
// concatenation for `Cow` preserves a borrowed value when
// either side is empty.
Cow::from("")
};
result += &line[idx..idx + len];
if !last_word.penalty.is_empty(){
result.to_mut().push_str(last_word.penalty);
}
lines.push(result);
// Advance by the length of `result`, plus the length of
// `last_word.whitespace` -- even if we had a penalty, we need
// to skip over the whitespace.
idx += len + last_word.whitespace.len();
}
}
but replace all lines.push(x) with counts.push(textwrap::core::display_width(&x), where counts is the vec to return.
The downside is that there could be a lot of duplicate code.
The text was updated successfully, but these errors were encountered:
I roughly scan over the code, and don't find similar functionality. So this post can be regarded as a feature request, and I'm glad to PR if possible.
Proposal
I'm seeking for a function to try wrapping a paragraph, and return a vec of displayed widths. The signature of such function could be:
An example use would be:
Use case
For example, one may want to find the smallest width such that any wrapped line won't protrude out, without the need to actually wrap the text into string.
Implementation
A naive implementation is to mimic this function:
textwrap/src/wrap.rs
Lines 215 to 292 in 6397036
but replace all
lines.push(x)
withcounts.push(textwrap::core::display_width(&x)
, wherecounts
is the vec to return.The downside is that there could be a lot of duplicate code.
The text was updated successfully, but these errors were encountered: