Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non breaking words #193

Closed
truchi opened this issue Jun 29, 2020 · 2 comments · Fixed by #194
Closed

Non breaking words #193

truchi opened this issue Jun 29, 2020 · 2 comments · Fixed by #194

Comments

@truchi
Copy link

truchi commented Jun 29, 2020

Hello,

When I run:

let text = "textwrap: a small library for wrapping text.";

println!(
    "{}",
    textwrap::Wrapper::new(1).break_words(false).fill(text)
);

I get the non-expected results:

textwrap:
 
a
small
 librar
y
 fo
r
 wrappin
g
 text
.

Yet I expect:

textwrap:
a
small
library
for
wrapping
text.

Same with 2, 3, 4 ...

Thank you!

@mgeisler
Copy link
Owner

mgeisler commented Jul 1, 2020

Hi @truchi! Oh wow, that looks odd... I'll take a look and try to fix it as soon as possible. Thanks for the report.

mgeisler added a commit that referenced this issue Jul 1, 2020
Words wider than the line width were not handled correctly. The line
width computation was messed up and this resulted in random-looking
whitespace in the resulting lines.

Fixes #193.
mgeisler added a commit that referenced this issue Jul 1, 2020
Words wider than the line width were not handled correctly. The line
width computation was messed up and this resulted in random-looking
whitespace in the resulting lines.

Fixes #193.
mgeisler added a commit that referenced this issue Jul 2, 2020
mgeisler added a commit that referenced this issue Jul 2, 2020
@truchi
Copy link
Author

truchi commented Jul 3, 2020

You are welcome, sir. Thank you for the fix!

mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants