-
Notifications
You must be signed in to change notification settings - Fork 45
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
No explicit control over CR LF line ending #453
Comments
Hey @edio, thanks for opening the issue. Super exciting that textwrap is used in the editor! You're not missing anything, textwrap is hard-coded to split on I've been thinking of Searching a bit, it seems that this way of thinking comes from how languages like C++ handle text mode files. Rust doesn't have a text mode, so I think my way of thinking is outdated :-D Now, I see a few different approaches for handling this:
Out of the options, I think the first two are the best. Since Textwrap tries to be useful for many use-cases, I will be happy to see a custom enum like you suggest. I agree that two enum variants ought to be enough for now. Since we split the input just once, I think the performance impact should be negligible, but please compare % cargo criterion fill_optimal_fit_ascii/4800 before and after to make sure. |
Another thing: I think Helix is the first place which uses |
@mgeisler , thanks for the response. I considered transforming the input before feeding it to textwrap, but that seemed inefficient (and most of all cumbersome).
Perhaps I should summon @kirawi here, who's been handling the issue in the helix repo and, I assume, familiar with the helix codebase (unlike me). EDIT: I misread. The proposal was to use |
My thinking was that the client (the caller of Thanks for the pull request, I'll go take a look now! |
@mgeisler , I benchmarked IMO, if there's no explicit control over the line ending, Anyway switching to If we do |
I like what you've done in #454: let the caller of Let us continue discussing there! |
Fixed by #454, thanks! |
This was a semver breaking change since fn textwrap_options() -> textwrap::Options<'static> {
textwrap::Options {
width: textwrap::termwidth(),
initial_indent: " ",
subsequent_indent: " ",
break_words: true,
wrap_algorithm: textwrap::WrapAlgorithm::OptimalFit(Default::default()),
word_separator: textwrap::WordSeparator::UnicodeBreakProperties,
word_splitter: textwrap::WordSplitter::NoHyphenation,
}
} breaks when updating from v0.15.0 to v0.15.1 |
Hi @Arnavion, oh no, I didn't think of that... Thanks for noticing! I'll yank the release and redo the release on the weekend. I'm curious through, do you have code like that? Why would you write it like that when |
Yes. It failed to compile yesterday and that's why I started investigating and reached here.
I wanted to initialize all the fields with values of my choice, so the builder would be more verbose than setting the fields directly. Also, having a struct with |
Yeah, I get that — I made them public to make it easy to reassign a few fields when needed. I just didn't expect anybody to actually use the struct literal syntax itself. Thanks for letting me know, I'll fix it as soon as I can. |
Yeah, in that case you can make it |
This allows us to add more fields in the future without breaking backwards compatibility. This was pointed out in #453.
Thanks @Arnavion, I've yanked 0.15.1 and released 0.16.0 instead. |
Please unyank 0.15.1, clap 3.2.22 explicitly depends on it. |
0.15.0 should have been rereleased as 0.15.2 to make sure downstream users explicitly depending on 0.15.1 don't get stuck. |
If any crate depends on ^0.15.1 explicitly, it would normally be doing so because it depends on API newly added in 0.15.1, so it wouldn't work with 0.15.0 released as 0.15.2. So doing what you suggest would be pointless in general. That said, clap 3 seems to have updated to 0.15.1 without depending on the change in 0.15.1 ( clap-rs/clap@2fd5507 ), so it would indeed work with 0.15.0 re-released as 0.15.2. Why it updated its dep for no reason is a mystery... |
This is wrong. If I add a dependency to my system I always take the biggest version number, because then that enforces I don't rely on a bugfix without doing so explicitly, and it also circumvents issues with crates that don't believe in minor version bumps (e.g. serde). Anyway it's good practice to always rerelease a bigger version number whenever a version is yanked to restore whatever was before. |
That's fine, but I hope you defensively bump every dep you have in every commit you make, no matter how unrelated it is. After all you might have added foo dep at its latest version last week, but your clean build today might be relying on a new bugfix it released yesterday. Otherwise you're not achieving the safety you desire :) (The only way this can be solved for sure is with Anyway, this is not the place to argue about it, and I agree that there's no harm in releasing 0.15.2. |
Helix editor recently added a feature to reflow a piece of text; helix uses textwrap for this
There's an issue, where reflow does not work correctly if
CRLF
sequence (\r\n
) is used as a line terminatorhelix-editor/helix#2645
helix does not support
CR
ending (pre macosx), but I guess, the issue would manifest with it as well.As far as I can see, textwrap does not account for different line ending, there's no configuration option with which we could tune textwrap behavior.
Did I miss anything? Is there a way to support
CRLF
in textwrap?If not, I'd be willing to contribute a fix.
My initial idea is to introduce another option into the
Options
struct, namedline_ending
(orline_terminator
as a fancier alternative). To keep things tight, I'd express it asenum
(we can always create something likeCustom
should we want to support an arbitrary byte sequence later, but I highly doubt that). How does that sound?The text was updated successfully, but these errors were encountered: