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

Terminal doesn't handle multiple OSC 1337 or OSC 7 escape sequences correctly #234332

Open
rzhw opened this issue Nov 21, 2024 · 1 comment
Open
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@rzhw
Copy link

rzhw commented Nov 21, 2024

Type: Bug

From VSCode:

  1. Create either of the following scripts as test.py, and follow the below instructions:

OSC 1337:

import os
import sys

script_dir = os.path.dirname(os.path.realpath(__file__))

if not os.path.exists("foo"):
    print("make a folder called foo first")
    quit()

new_cwd = os.path.join(script_dir, "foo")
print(f"changing cwd OSC 1337 to {new_cwd}", flush=True)
sys.stdout.write(f"\033]1337;CurrentDir={new_cwd}\007")
print("../test.py:37:1: error: use of undeclared identifier 'sdfsfds'")
print("delay...")

# print(f"changing cwd OSC 1337 to {script_dir}", flush=True)
# sys.stdout.write(f"\033]1337;CurrentDir={script_dir}\007")
# print("./test.py:37:1: error: use of undeclared identifier 'sdfsfds'")
# print("delay...")

OSC 7:

import os
import sys

script_dir = os.path.dirname(os.path.realpath(__file__))

if not os.path.exists("foo"):
    print("make a folder called foo first")
    quit()

new_cwd = os.path.join(script_dir, "foo")
print(f"changing cwd OSC 7 to {new_cwd}", flush=True)
sys.stdout.write(f"\033]7;file://localhost{new_cwd}\007")
print("../test.py:37:1: error: use of undeclared identifier 'sdfsfds'")
print("delay...")

# print(f"changing cwd OSC 7 to {script_dir}", flush=True)
# sys.stdout.write(f"\033]7;file://localhost{script_dir}\007")
# print("./test.py:37:1: error: use of undeclared identifier 'sdfsfds'")
# print("delay...")
  1. Run python3 test.py from the inbuilt terminal.

  2. Observe that Ctrl/Cmd+Click on ../test.py opens test.py as expected.

  3. Uncomment the commented lines.

  4. Run python3 test.py.

  5. Observe that Ctrl/Cmd+Click on ../test.py does not open it. Instead, VSCode spins a while and then pops a file picker.

  6. Observe that Ctrl/Cmd+Click on ./test.py opens test.py as expected.

From iTerm2:

  1. Run python3 test.py, with the lines either commented out or not.

  2. Observe that in both cases, Cmd+Click on ../test.py and ./test.py open test.py as expected.

This seems particularly notable as OSC 1337 is an iTerm2 proprietary escape sequence.

VS Code version: Code 1.95.3 (Universal) (f1a4fb1, 2024-11-13T14:50:04.152Z)
OS version: Darwin arm64 24.2.0

@rzhw rzhw changed the title Terminal doesn't accept multiple OSC 1337 or OSC 7 escape sequences in succession Terminal doesn't handle multiple OSC 1337 or OSC 7 escape sequences correctly Nov 21, 2024
@meganrogge meganrogge assigned Tyriar and unassigned meganrogge Nov 21, 2024
@Tyriar
Copy link
Member

Tyriar commented Nov 21, 2024

I think the problem here is that we tie the cwd to the command being run, not the line range. Changing cwd inside a command like this isn't supported and I'm a little surprised to see it works in iTerm2, but I guess they just went the line route instead of linking it to the full execution. @rzhw have you read somewhere official that this is supposed to work? I think you stumbled upon some largely undefined behavior here.

@Tyriar Tyriar added the info-needed Issue requires more information from poster label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants