Skip to content

adjust where prompt markers go#5491

Merged
fdncred merged 2 commits intonushell:mainfrom
fdncred:tweak_shell_integration
May 10, 2022
Merged

adjust where prompt markers go#5491
fdncred merged 2 commits intonushell:mainfrom
fdncred:tweak_shell_integration

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented May 9, 2022

Description

The prompt markers were being placed at the wrong spot.

Hopefully this fixes #5449 once and for all.

Tests

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo build; cargo test --all --all-features to check that all the tests pass

@fdncred fdncred marked this pull request as draft May 9, 2022 23:29
@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 9, 2022

ugh - works great in kitty. stinks in iterm and terminal.app. not sure why.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 10, 2022

This is aggravating. I think what the problem is that Kitty uses one thing to mark, iTerm2 uses another, WezTerm uses another. We may have to remove this functionality altogether and allow people to use it in the pre-prompt and pre-execute hooks.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 10, 2022

Research (K=Kitty, I=iTerm2, W=WezTerm) -

  1. just before starting to draw the PS1 prompt
    K - 133;A
    I - OSC 133 ; A ST
    W - printf "\033]133;A;cl=m;aid=%s\007" "$$"

  2. Just before starting to draw the PS2 prompt
    K - 133;A;k=s (k=s is for contiuation line)
    I - OSC 133 ; B ST
    W - PS1='[\e]133;P;k=i\a]'$PS1'[\e]133;B\a]' (k=i means default prompt)
    PS2='[\e]133;P;k=r\a]'$PS2'[\e]133;B\a]' (k=r means right prompt )

  3. Just before running command
    K - 133;C
    I - OSC 133 ; C ST
    W - printf "\033]133;C;\007"

  4. Command has finished
    K - ? maybe the same as iterm2 since it refers to the iterm2 docs?
    I - OSC 133 ; D ST
    W - printf "\033]133;D;%s;aid=%s\007" "$ret" "$$"

Docs on semantic prompts
https://gitlab.freedesktop.org/Per_Bothner/specifications/blob/master/proposals/semantic-prompts.md

@schrieveslaach
Copy link
Copy Markdown
Contributor

I was looking into this in a TDD way. My idea was that the nu! macro can be invoked without -c and types the commands through stdin so that it renders the prompt into the output. That would enable the capturing of all chars (including the prompt) and could be used to run some assertions. However, I was unable to make that working.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 10, 2022

@schrieveslaach I have just had a minor breakthrough with the latest main. I was able to use the pre-execute hook and the pre-command hook, to get this to work. So, I'm contemplating now whether this needs to be in nushell at all, epecially given that some terminals use different ways of doing this marking. Ping me here if you want to know what blocks I used so you can try it out yourself.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 10, 2022

I think I finally figured it out. Markers are working in terminal.app, iterm2, wezterm, and kitty.

@fdncred fdncred marked this pull request as ready for review May 10, 2022 21:14
@fdncred fdncred merged commit 94a9380 into nushell:main May 10, 2022
@fdncred fdncred deleted the tweak_shell_integration branch May 10, 2022 21:33
@schrieveslaach
Copy link
Copy Markdown
Contributor

@fdncred, I tested the current main branch. Its working fine. Thanks for fixing!

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 11, 2022

@schrieveslaach you don't know how happy that makes me feel. this was a real battle for me to figure out how to do it. I would've given up if it weren't for the new hooks functionality.

@schrieveslaach
Copy link
Copy Markdown
Contributor

I'm happy to use Nushell. 😉 Thanks for working on it.

fennewald pushed a commit to fennewald/nushell that referenced this pull request Jun 27, 2022
* adjust where prompt markers go

* marks are working, yipee!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last Output Capturing Does not Work

2 participants