zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
21.33k stars 644 forks source link

Pasting some specific text causes different text to paste, `C-c` to break #1726

Open max-sixty opened 2 years ago

max-sixty commented 2 years ago

Basic information

zellij --version: zellij 0.31.4 stty size: 133 178 uname -av or ver(Windows): Darwin Maximilian_RoosVDI- 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64

List of programs you interact with as, PROGRAM --version: output cropped meaningful, for example:

I'm seeing very odd behavior when pasting some specific text in zellij. I'm not seeing this when using Alacritty without Zellij.

I've tried to find the smallest piece of text that this applies to, but haven't managed to reduce it much. To the extent this doesn't easily reproduce for others, I can do more reduction, and attach log files etc.

When pasting this text into alacritty, starting with a prompt of echo ':

# Output of code command looks like
# `extensions/visualstudioexptteam.vscodeintellicode-1.2.14/cache/models.json`
# Alternatively — the path is already created, so we could read it from the
# path.
INTELLICODE_VERSION=$(code --user-data-dir=data/ --list-extensions --show-versions | rg -o 'intelli.*@(.*)' -r '$1')
INTELLICODE_PATH=data/extensions/visualstudioexptteam.vscodeintellicode-${INTELLICODE_VERSION}
# Model URL is something like
# https://intellicodeprodstorage.blob.core.windows.net/models-prod-output/Output_88630A1B4C077752096ECAA576B92C7D3FA1_9BA695AD4C514C32A5D0AC9B02846CD7?skoid=511b33f5-16ee-4db4-a582-21e2be0519ae&sktid=975f013f-7f24-47e8-a7d3-abc4752bf346&skt=2021-07-22T06%3A24%3A16Z&ske=2021-07-23T06%3A24%3A16Z&sks=b&skv=2020-02-10&sv=2020-02-10&se=2021-07-22T07%3A34%3A59Z&sr=b&sp=r&sig=XI3m1%2BIHKIrr6yB8EciA3UZ7Xzjwd7GhqYjiHCsRXrc%3D
# It's too long for wget to write as a filename!
MODEL_URL=$(curl https://prod.intellicode.vsengsaas.visualstudio.com/api/v1/model/common/python/intellisense-members-lstm-pylance/output/latest | jq -r '.. | .readSasToken? //empty')
MODEL_NAME=$(echo $MODEL_URL | rg -o 'Output_(.*)\?' -r '$1')
  1. it produces a different output — note the repeated INTELLICODE_PATH as an example:
    ❯ echo '# Output of code command looks like
    # `extensions/visualstudioexptteam.vscodeintellicode-1.2.14/cache/models.json`
    # Alternatively — the path is already created, so we could read it from the
    # path.
    INTELLICODE_VERSION=$(code --user-data-dir=data/ --list-extensions --show-versions | rg -o \'intelli.*@(.*)\' -r \'$1\')
    INTELLICODE_PATH=data/extensions/visualstudioexptteam.vscodeintellicode-${INTELLICODE_VERSION}
    # Model URL is something like
    # https://intellicodeprodstorage.blob.core.windows.net/models-prod-output/Output_88630A1B4C077752096ECAA576B92C7D3FA1_9BA695AD4C514C32A5D0AC9B02846CD7?skoid=511b33f5-16ee-4db4-a582-21e2be0519ae&sktid=975f013f-7f24-47e8-a7d3-abc4752bf346&skt=2021-07-22T06%3A24%3A16Z&ske=2021-07-23T06%3A24%3A16Z&sks=b&skv=2020-02-10&sv=2020-02-10&se=2021-07-22T07%3A34%3A59Z&sr=b&sp=r&sig=XI3m1%2BIHKIrr6yB8EciA3UZ7Xzjwd7GhqYjiHCsRXrc%3D
    # It\'s too long for wget to write as a filename!
    MODEL_URL=$(curl https://prod.intellicode.vsengsaas.visualstudio.com/api/v1/model/common/python/intellisense-meintelli.*@(.*)\' -r \'$1\')
    INTELLICODE_PATH=data/extensions/visualstudioexptteam.vscodeintellicode-${INTELLICODE_VERSION}
    # Model URL is somet
  2. C-c no longer works. I need to exit Zellij. Other keys respond.

Thanks a lot as ever!

raphCode commented 2 years ago

The following refers to bash:

I played around a bit and also got Ctrl-C to break once but cannot relieably reproduce. Weird.

The duplicate text is partly because of the text you enter: The echo ' starts a shell string which runs until the apostrophe in # It's too long. (Actually there are more ' hidden in between but they cancel out, by stopping the old string literal and restarting a new one) The # to comment out lines is not parsed in strings. After the <Enter> from this line, the echo command is executed and repeats all lines until this part.

To me this even happens outside of zellij when I paste only up until this line.

Since you pasted more lines than that, there is now a race between echo writing terminal output and the terminal emulator "typing" the clipboard content. Zellij buffers and alters the timing of writing to the terminal, so this might explain why you see different results outside or inside zellij.

max-sixty commented 2 years ago

Thanks for the explanation! Can I ask which shell you're using? Oddly I can reproduce in fish every time. Possibly fish is escaping ' characters, whereas bash isn't, and so I can reproduce on fish but not bash.

I'm not sure if you have access to fish. It does feel like an invasive problem — that pasting isn't reliable — though maybe this is an extreme corner case?

Let me know anything I can do from my end. Thanks!

raphCode commented 2 years ago

Possibly fish is escaping ' characters

Yep, I just tried pasting it in fish and it seems it automatically adds a backslash to escape ' when pasting it.

On my two Arch machines I get the expected output as well as Ctrl-C working afterwards as long as I entered some text in the prompt. In an empty prompt, fish doesn't do anything with Ctrl-C, before and after pasting the text.

fish 3.5.1 and alacritty 0.10.1

screenshot ![image](https://user-images.githubusercontent.com/15750438/190651258-3fb22071-a2ae-48a2-9a28-26c248a8a5ed.png)
max-sixty commented 2 years ago

I tried some more and got some surprising results!

I get the error only if it's the first command in a new tab. If I've already run an echo 'hello world' in that tab, then I get the expected result. It also doesn't manifest on just opening a new pane.

Though it looks like from your screenshot that you might not get this, since that looks like it might be the first command in that tab?

raphCode commented 2 years ago

In the screenshot I pressed Ctrl-L before the command to have a clean terminal.

But I just tried again with the first command being echo ' and then pasting the text from the first post. As fish is not my default shell, I opened zellij with SHELL=fish zellij and tried in the first pane as well an extra new tab I opened. Both times it worked as expected, not showing the bug.

Do you maybe have some shell init scripts like .bashrc (.fishrc?) that you could try disabling?

max-sixty commented 2 years ago

OK, thanks again @raphCode

It's definitely not exclusively a Zellij issue, but after debugging for a while I can't exactly work it out. So let me leave my latest findings here in case anyone hits something similar in the future. Fine to close in the meantime.

Using fish --no-config doesn't reproduce the error, either in or outside Zellij.

Specifically running:

fish --no-config
# we need this binding to do the paste
bind \cv fish_clipboard_paste
echo ' # then paste
# the result comes out fine

But all is not resolved — I still get an issue exclusively in Zellij without --no-config with an empty fish.config. So I think it's likely to be some native fish function or similar, interacting weirdly with Zellij. Pasting the text above in vs outside zellij, prefixed by echo ' as above, and suffixed by ' > [no-]zellij.txt, yields this diff:

diff --git a/no-zellij.txt b/zellij.txt
index 1536a79..ed5e46c 100644
--- a/no-zellij.txt
+++ b/zellij.txt
@@ -7,5 +7,6 @@ INTELLICODE_PATH=data/extensions/visualstudioexptteam.vscodeintellicode-${INTELL
 # Model URL is something like
 # https://intellicodeprodstorage.blob.core.windows.net/models-prod-output/Output_88630A1B4C077752096ECAA576B92C7D3FA1_9BA695AD4C514C32A5D0AC9B02846CD7?skoid=511b33f5-16ee-4db4-a582-21e2be0519ae&sktid=975f013f-7f24-47e8-a7d3-abc4752bf346&skt=2021-07-22T06%3A24%3A16Z&ske=2021-07-23T06%3A24%3A16Z&sks=b&skv=2020-02-10&sv=2020-02-10&se=2021-07-22T07%3A34%3A59Z&sr=b&sp=r&sig=XI3m1%2BIHKIrr6yB8EciA3UZ7Xzjwd7GhqYjiHCsRXrc%3D
 # It's too long for wget to write as a filename!
-MODEL_URL=$(curl https://prod.intellicode.vsengsaas.visualstudio.com/api/v1/model/common/python/intellisense-members-lstm-pylance/output/latest | jq -r '.. | .readSasToken? //empty')
-MODEL_NAME=$(echo $MODEL_URL | rg -o 'Output_(.*)\?' -r '$1')
+MODEL_URL=$(curl https://prod.intellicode.vsengsaas.visualstudio.com/api/v1/model/common/python/intellisense-meintelli.*@(.*)' -r '$1')
+INTELLICODE_PATH=data/extensions/visualstudioexptteam.vscodeintellicode-${INTELLICODE_VERSION}
+# Model URL i

...so something coincident with Zellij is cutting off some of the pasted text, and running some of the echo command to produce INTELLICODE_PATH... at the end.

The mystery continues :)

benediktms commented 2 years ago

I'm getting the same issue. I'm also using alacritty but with zsh. C-C(C-S-c) without Zellij works fine. I'm noticing it when trying to paste passwords into the terminal (specifically an ssh key password) that I copy to the register via a password manager. Copying manually and pasing into zellij will work again, it's only during the password enter that this breaks for me.

imsnif commented 2 years ago

@benediktms - are you by any chance using a version lower than 0.31.4? This sounds like a different bug that was fixed.

benediktms commented 2 years ago

@imsnif I was indeed on 0.31.3, updated and everything works fine. Thanks you :)

max-sixty commented 6 months ago

Update on 0.39.2:

I guess that Cmd-v pastes from the OS, which simulates typing? While Ctrl-v pastes from fish? (this area is beyond my understanding...)