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
Newlines not pasted correctly in Nano #994
Comments
As far as I can tell, this is really a bug in nano http://savannah.gnu.org/bugs/?49176 It cannot distinguish between pasted and typed text. And when typing it binds the newline character to justify instead of newline, for some absurd reason. The correct fix is for nano to implement bracketed paste mode, which is both more secure and a better design. It's 2018 even most shells implement bracketed paste, let alone editors. You can work around it by following the advice in that bug report to unbind Ctrl-J (which is the newline character) or use a better editor. I am guessing that other terminal emulators work around this brokenness by preprocessing the pasted text, replacing \n by \r. I suppose kitty could do the same, although this kind of hackery breaks my heart. A simple patch for kitty to do that would be: diff --git a/kitty/window.py b/kitty/window.py
index 92d2181d..6c202c6f 100644
--- a/kitty/window.py
+++ b/kitty/window.py
@@ -478,6 +478,10 @@ class Window:
if len(text) == len(new_text):
break
text = new_text
+ else:
+ # Workaround for broken editors like nano,
+ # see https://github.com/kovidgoyal/kitty/issues/994
+ text = b'\r'.join(text.splitlines())
self.screen.paste(text)
def copy_to_clipboard(self): |
That's not the only weird behavior from Nano, actually. 3.0 introduced a regression (again, only in kitty) where the backspace key would delete the preceding word, rather than the preceding char. It was fixed in 3.1, though it didn't show up in the changelog. Weird stuff. |
On another note, I installed micro to test it out, and (again, only in kitty) I get this error when attempting to run it:
Should I create a new issue for that? |
Helpful for a different reason, but not what I'm talking about. I'm using micro locally. |
I just tried micro 1.4.1 and it works fine in kitty. The link I posted is pretty much the only reason for that error. The only other reason would be if the software generating it ignores the TERMINFO environment var, which you can work around by copying the kitty terminfo files to ~/.terminfo or /usr/share/terminfo |
I'll figure it out. Main issue is the nano thing. I'd figure out another editor to use, but my main use is to c&p into an ssh session on a remote server that I can't add editors to.
…On Wed, Sep 19, 2018 at 10:01 PM, Kovid Goyal ***@***.***> wrote:
https://sw.kovidgoyal.net/kitty/faq.html#i-get-errors-about-the-terminal-being-unknown-or-opening-the-terminal-failing-when-sshing-into-a-different-computer
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#994 (comment)), or [mute the thread](https://github.com/notifications/unsubscribe-auth/AMYVaC2e5ZxuAb2RQ3l0hc92z-zeAJAPks5ucvcCgaJpZM4WwsUa).
|
Well try the patch I posted above, it should do the trick. |
In regards to the patch, works like a charm. I'll keep this issue open, though (unless you want to close it), since it is still an issue that exists in the release version of kitty. In regards to micro, the distro I use has a slightly out-of-date version of kitty (0.11.3). I installed the newest version, and it worked without a hitch. |
For the record, I know it sucks to add these kinds of workarounds. If I were in your place, being the contrarian that I am, I'd likely refuse to patch it. But I appreciate you doing so, and within the day no less. Keep up the good work!
…On Wed, Sep 19, 2018 at 11:38 PM, Kovid Goyal ***@***.***> wrote:
Closed [#994](#994) via [3f0b52b](3f0b52b).
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#994 (comment)), or [mute the thread](https://github.com/notifications/unsubscribe-auth/AMYVaDeGcrgE4LIW9GYSwIIqQYBufwpkks5ucw3DgaJpZM4WwsUa).
|
So I updated to the newest version of Kitty, which includes the fix for this. Despite my window.py file having the patched code (verified by viewing the file itself), newlines still aren't correctly pasted in nano 3.1. I'm at a loss. |
You sure you are running the updated kitty? |
I was sure, I even ran |
@kovidgoyal, the workaround actually caused another issue. Let's say I'm copying a cli command (with newline) in emacs, and then want to paste it into the terminal. What I'm expecting is that the command will be executed immediately. However, the workaround striped the newline in my paste, which means I'll have to type an enter in the terminal. |
You should never copy paste into a shell and have in interpret newlines. That is a huge security risk. See bracketed paste mode, which kitty and most modern shells support. |
Why would there be a security concern? Are you suggesting that copying "ls\n" is not encouraged? |
Sometimes I might need to copy multiple commands in a single paste, e.g., "cd\nls\n". For this case, kitty would only copy "cd\nls", instead of "cd\nls\n". Is your point that we should not include \n in any paste? |
Google bracketed paste |
My point is that you should never paste commands that auto-execute into |
Here is a demonstration of a possible attack: https://thejh.net/misc/website-terminal-copy-paste |
I appreciate that you guys pointed out the security risk, and I agree with you guys on it. I think maybe I provided a bad example. What we are discussing are two complete different issues:
|
How is it supposed to tell the user bracketed paste is not enabled? And |
It does not matter whether the terminal enables the bracketed paste mode. The point is that a good terminal should never change users intent silently (in this case, the content users try to paste), no matter bracketed paste mode is enabled or not. Btw, I don't believe iterm2 and mintty enables this bracketed paste mode by default. |
bracketed paste mode is not enabled by default in kitty either. |
I am having this same problem on |
I have the same problem. After downgrading to version 4.7 I fixed this problem... |
Seems like |
Thank you @Tockra , you saved my life. I'm a vim unaware idiot maybe. But this bug with nano almost made me giving up on kitty. I downgrade nano (4.3, eoan package on ubuntu) and it works. Before this i tried to compile the last kitty version, i also tried to remove the patch : EDIT:
|
With the latest version of kitty and nano 2.9.8, 3.0, and 3.1, the following text:
is interpreted as the following when pasting into nano within kitty:
gnome-terminal pastes this text correctly, newlines and all. When pasting into kitty outside of nano, the newlines are parsed correctly.
The text was updated successfully, but these errors were encountered: