-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Replacing \r\n line endings with \r line endings #3449
Conversation
Does the |
It solves the problem if we're not concerned about stripping all \n characters; the solution here only changes \r\n pairs. |
ah, interesting. I wonder how common a degenerate clipboard is that contains |
I tend to think it's warranted to err on the side of conservative character-stripping here. An argument could be made to convert |
Oops, misread the comment a bit. Anyway:
|
Sounds good to me. Thanks for digging in. 😄 |
@d-bingham @DHowett-MSFT When the string is long and multiple lines, can the following scheme reduce the memory copy? std::wstring ReplaceNewline(std::wstring_view str) {
std::wstring s;
s.reserve(str.size());
while (!str.empty()) {
auto pos = str.find(L"\r\n");
if (pos == std::wstring::npos) {
s.append(str);
break;
}
s.append(str.substr(0, pos)).append(L"\n");
str.remove_prefix(pos + 2);
}
return s;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Handy links: |
Err... apologies if I'm missing something, but:
Unix-land (and pretty much everything non-Windows -- "more universal"?), uses Shouldn't this patch/feature be changing Edit: note if this was tested by pasting while in, say, a ssh session to a Linux host, most unix ttys have the |
@vvuk you’re correct for textual data serialized to disk, but it appears (based on a couple popular terminal emulators available today) that the universal encoding used by terminal emulators for a newline is Windows Terminal’s backing pseudoterminal infrastructure transforms an incoming carriage return (and an incoming line feed, which incidentally is the cause of the problem this PR fixed) into a key event encoding Enter. That is handled on the other end in an application-specific manner. |
I guess, in short, the Windows PTY always acts in |
Ahh, got it. I was indeed missing something. Thanks for the explanation :) |
It is well more interesting to replace \r\n by \n. Indeed, thanks to this change we can paste several line in the terminal without executing them. |
Summary of the Pull Request
References
#1091
#1094
#2390
#3314
PR Checklist
Detailed Description of the Pull Request / Additional comments
Combination of the PRs #1094, #2390, and #3314, especially as discussed in #3314.
In short, this changes line endings from Windows-space \r\n to the more universal \r.
Validation Steps Performed
Copied and pasted text into the terminal without the patch, line endings were doubled.
With the patch, line endings weren't doubled.