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

nushell replicates prompt line with every keystroke on wezterm #5585

Open
CGMossa opened this issue May 19, 2022 · 46 comments
Open

nushell replicates prompt line with every keystroke on wezterm #5585

CGMossa opened this issue May 19, 2022 · 46 comments
Labels
line editor Issues related to reedline upstream problem with upstream dependency

Comments

@CGMossa
Copy link

CGMossa commented May 19, 2022

Describe the bug

Every keystroke duplicates the prompt line for no reason.

See wez/wezterm#1999.

I had to post a bug here, as I'm beginning to think that this is
very much tied to nushell and not the wezterm (or atleast both).

How to reproduce

Nothing but type in your terminal and see the prompt replicate.

Expected behavior

I don't expect the terminal to fill up with the line before the keystroke.

Screenshots

No response

Configuration

key value
version 0.62.0
branch
tag
build_os windows-x86_64
rust_version rustc 1.60.0 (7737e0b5c 2022-04-04)
rust_channel stable-x86_64-pc-windows-msvc
cargo_version cargo 1.60.0 (d1fd9fe2c 2022-03-01)
pkg_version 0.62.0
build_time 2022-05-09 20:50:11 +02:00
build_rust_channel release
features default, trash, which, zip
installed_plugins

Additional context

I'm on Windows. I tried with nightly wezterm, latest stable of nu, with no configuration in wezterm, and with default configuration for nushell; We also tried to no configuration files for nushell.

@fdncred
Copy link
Collaborator

fdncred commented May 19, 2022

one idea is to try to compile and run reedline by itself, just to see if there's something odd going on there.

@CGMossa
Copy link
Author

CGMossa commented May 19, 2022

I've installed nu from main, i.e. 0.62.1 and the issue is not present here.
I did this by

cargo install nu --git https://github.com/nushell/nushell.git

@fdncred
Copy link
Collaborator

fdncred commented May 19, 2022

let's close this if the problem doesn't exist any longer. thanks!

@fdncred fdncred closed this as completed May 19, 2022
@hornyjailfish
Copy link

hornyjailfish commented Jun 1, 2022

Issue still presents if linebreak characters (\n \f \t) in right prompt and caret on last terminal line (frequently after long outputs)
tested on wezterm alacritty and conemu \n\r causes issue on all of them

@hustcer hustcer reopened this Jun 1, 2022
@fdncred
Copy link
Collaborator

fdncred commented Jun 1, 2022

I'm not sure how to reproduce this. Do I need to change my right prompt to something special?

@hornyjailfish
Copy link

  1. put something like "\n\r" (default newline sequence in windows) or "\nsomething" in let-env PROMPT_COMMAND_RIGHT = {}
  2. than move caret to last line in terminal (hold enter or ls big folder...whatever)
  3. type anything
prompt_linebreak.mp4

I tested with different escape symbols (win10)
Legend ? any character, + one or more character

  • conemu +?\b \f+ \n+ +\t+
  • wezterm \f \n+ \t+
  • alacritty \f+ \n+ \t

\r+ has no issue just overrides left prompt

Of course its edge case and i could define function preparing prompt with str trim or str replace
But if right prompt mandatory one liner i think it need some internal fixes

@fdncred
Copy link
Collaborator

fdncred commented Jun 2, 2022

Thanks for the information.

  1. I'm not sure it really matters but the default newline sequence in windows is \r\n instead of \n\r.
  2. I'm not really clear why one would want to put a CRLF in the right prompt. I'm really not sure what problem we're trying to solve. What's the real-world use case for having a CRLF or just a LF FF or Tab in the right prompt?

@jiahut
Copy link

jiahut commented Aug 19, 2022

this still exists at win10/wezterm/nu0.67.0

@CGMossa
Copy link
Author

CGMossa commented Aug 19, 2022 via email

@fdncred
Copy link
Collaborator

fdncred commented Aug 19, 2022

I only notice this on the Windows version of WezTerm. The Mac version works great. Does this still happen with shell_integration set to false in the nushell config.nu?

@jiahut
Copy link

jiahut commented Aug 22, 2022

I only notice this on the Windows version of WezTerm. The Mac version works great. Does this still happen with shell_integration set to false in the nushell config.nu?

it works at win10/wezterm/nu0.67.0

@gsuuon
Copy link

gsuuon commented Aug 24, 2022

I only notice this on the Windows version of WezTerm. The Mac version works great. Does this still happen with shell_integration set to false in the nushell config.nu?

Setting this to false fixes the issue for me as well - wezterm 20220807-113146-c2fee766, nu 0.67, win 10

@fdncred
Copy link
Collaborator

fdncred commented Aug 24, 2022

It's sad that WezTerm behaves this way to our ansi escape sequences. I have no idea why it repeats the prompt with every character typed. It's not like we're sending the escape sequences for every character. It only happens around the time the prompt is drawn.

@wez
Copy link

wez commented Aug 26, 2022

The way that PTYs work on Windows is a bit different from unix systems.
The ConPTY layer needs to translate from the stream of escapes and apply that data to the internal windows console screen model, and then translates from that to a stream of output escapes. That processed stream is what wezterm, conemu and alacritty see.

What I suspect may be happening here is that you are tickling an edge case that causes conpty to emit something unexpected that results in the output shown above.

Earlier comments indicate that this isn't a wezterm issue and that it manifests in other windows terminals.

In wezterm, you can use wezterm ssh host to use its integrated ssh client to connect to a remote system and bypass using the ConPTY layer. I suspect that if you use that to run a remote nushell with the same configuration you won't be able to reproduce this problem.

I would recommend opening an issue at https://github.com/microsoft/terminal to get input from the team that owns ConPTY who can perhaps advise on how to deal with this.

@wez
Copy link

wez commented Aug 26, 2022

See wez/wezterm#2442 (comment) for an example of how surprising some of the conpty-transformed output can be

@fdncred
Copy link
Collaborator

fdncred commented Aug 26, 2022

@wez Thanks a bunch for chiming in and giving us your perspective!!

Earlier comments indicate that this isn't a wezterm issue and that it manifests in other windows terminals.

We definitely see a pretty serious flicker with Windows Terminal Preview but not in Windows Terminal, nor Alacritty. We have an issue open already here microsoft/terminal#13710.

We haven't seen anything as serious as how WezTerm reacts on windows. Out of respect for you, I created this gif to show you what I see in Windows using WezTerm. I'm definitely not trying to lay this problem at your feet for fixing and running away, but I wanted to be clear about what I see as it's a little bit different than what is posted above.
wezterm

While I haven't tried every possible Windows terminal software, my usual test scenarios include Windows Terminal (sometimes preview too), Alacritty, and WezTerm.

PS. Can someone please test Wez's suggestion with wezterm ssh host? I don't really have a good way to do that since I don't use ssh anywhere.

@wez
Copy link

wez commented Aug 26, 2022

Please capture a terminal recording:

  • Launch wezterm. If possible, please use 80x24 (the default size) for the terminal dimensions as it helps to keep things smaller and easier to manage.
  • Inside that terminal run wezterm record to start a recording session.
  • Run through your reproduction steps with nushell.
  • Then type exit
  • You should see a message like:
*** Finished recording to /var/tmp/wezterm-recording-sF6B3u.cast.txt
  • Attach the file that it produced to this issue.

The file is an asciicast (compatible with https://asciinema.org/) and can also be replayed using wezterm replay.

The terminal recording allows me to replicate what is being sent to the terminal without requiring me to install the same applications as you and replicate your configuration for everything.

It would be great to get one capture on Windows and another on a unix system so we can compare what wezterm is seeing.

@micgao
Copy link

micgao commented Aug 28, 2022

I mentioned this over at #6214, but:

Setting "shell_integration: false" in config.nu fixes the problem (tested on alacritty, wezterm, and Windows Terminal)

@fdncred
Copy link
Collaborator

fdncred commented Aug 29, 2022

@wez
Here's the Windows one
wezterm-recording-hX0ZFK.cast.txt

Here's one from my m1 MacBookPro
wezterm-recording-paeqle.cast.txt

@wez
Copy link

wez commented Aug 29, 2022

If you wezterm replay those files on a unix system, then the windows one shows the stepping behavior, but the macos one does not.
If you replay them both on windows, then they both show the stepping behavior.

If I reduce the cast to just one of the lines that is causing problems:

\u001b[?25l\u001b[38;2;8;8;8m\u001b[48;2;206;215;207m\u001b[1m\r  \u001b[38;2;206;215;207m\u001b[48;2;52;101;164m  \u001b[38;2;228;228;228m~\u001b[38;2;206;215;207m\u001b[22m \u001b[38;2;52;101;164m\u001b[48;2;12;12;12m\u001b[38;5;14m\u001b[49m\u001b[1m \u001b[36mls\u001b[m \u001b[90m| where type == dir                          \u001b[K\u001b[38;2;96;96;96m\u001b[1m 0823 \u001b[38;2;211;215;207m\u001b[48;2;12;12;12m\u001b[22m\u001b[38;2;12;12;12m\u001b[48;2;211;215;207m 07:36:11 AM \u001b[m\r\n\u001b[K\u001b[23;15H\u001b[?25h

and run wezterm replay --explain on it:

> SENT
        Action(CSI(Mode(ResetDecPrivateMode(Code(ShowCursor)))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.03137255, 0.03137255, 0.03137255, 1.0))))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Intensity(Bold))))
        Action(Control(CarriageReturn))
        Print(" \u{f17a} ")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Print("\u{e0b0} \u{f015} ")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.89411765, 0.89411765, 0.89411765, 1.0))))))
        Print("~")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Intensity(Normal))))
        Print(" ")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Print("\u{e0b0}")
        Action(CSI(Sgr(Foreground(PaletteIndex(14)))))
        Action(CSI(Sgr(Background(Default))))
        Action(CSI(Sgr(Intensity(Bold))))
        Print(" ")
        Action(CSI(Sgr(Foreground(PaletteIndex(6)))))
        Print("ls")
        Action(CSI(Sgr(Reset)))
        Print(" ")
        Action(CSI(Sgr(Foreground(PaletteIndex(8)))))
        Print("| where type == dir                          ")
        Action(CSI(Edit(EraseInLine(EraseToEndOfLine))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.3764706, 0.3764706, 0.3764706, 1.0))))))
        Action(CSI(Sgr(Intensity(Bold))))
        Print("\u{e0b3} 0823 ")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.827451, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Action(CSI(Sgr(Intensity(Normal))))
        Print("\u{e0b2}")
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.827451, 0.84313726, 0.8117647, 1.0))))))
        Print(" 07:36:11 AM ")
        Action(CSI(Sgr(Reset)))
        Action(Control(CarriageReturn))
        Action(Control(LineFeed))
        Action(CSI(Edit(EraseInLine(EraseToEndOfLine))))
        Action(CSI(Cursor(Position { line: OneBased { value: 23 }, col: OneBased { value: 15 } })))
        Action(CSI(Mode(SetDecPrivateMode(Code(ShowCursor)))))
< RECV

it's a little bit easier to see that after printing the AM portion of the time, CarriageReturn and LineFeed are output, and that is what moves the cursor to the next line.

If you look at an equivalent line from the macOS output:

\u001b[?25l\u001b[24;1H\u001b[J\u001b[38;5;10m\u001b[1m\u001b]133;A\u001b\\\u001b[48;2;206;215;207;38;2;8;8;8m  \u001b[48;2;52;101;164;38;2;206;215;207m  \u001b[48;2;52;101;164;38;2;188;188;188m~\u001b[48;2;52;101;164;38;2;188;188;188m/\u001b[48;2;52;101;164;38;2;188;188;188ms\u001b[0m\u001b[48;2;52;101;164;38;2;188;188;188m/\u001b[48;2;52;101;164;38;2;188;188;188mf\u001b[0m\u001b[48;2;52;101;164;38;2;188;188;188m/\u001b[1;48;2;52;101;164;38;2;228;228;228mnushell\u001b[0m\u001b[48;2;52;101;164;38;2;206;215;207m \u001b[48;2;78;154;6;38;2;52;101;164m \u001b[48;2;78;154;6;38;2;12;12;12m main \u001b[48;2;196;160;0;38;2;78;154;6m \u001b[0m\u001b[48;2;196;160;0;38;2;0;0;0m✚1\u001b[0m\u001b[1;48;2;196;160;0;38;2;0;0;0m*\u001b[0m\u001b[48;2;12;12;12;38;2;196;160;0m\u001b[0m\u001b]133;B\u001b\\\u001b[38;5;14m\u001b[1m \u001b[38;5;5m\u001b[1m\u001b7\u001b[24;60H\u001b[38;2;96;96;96m\u001b[49m 0823 \u001b[0m\u001b[48;2;12;12;12;38;2;211;215;207m\u001b[48;2;211;215;207;38;2;12;12;12m 06:54:58 PM \u001b[0m\u001b8\u001b[0m\u001b[1;36mls\u001b[0m | \u001b[1;36mwhere\u001b[0m \u001b[32ms\u001b[0m\u001b7\u001b[90mize > 100b\u001b[0m\u001b8\u001b[?25h

and --explain it:

        Action(CSI(Mode(ResetDecPrivateMode(Code(ShowCursor)))))
        Action(CSI(Cursor(Position { line: OneBased { value: 24 }, col: OneBased { value: 1 } })))
        Action(CSI(Edit(EraseInDisplay(EraseToEndOfDisplay))))
        Action(CSI(Sgr(Foreground(PaletteIndex(10)))))
        Action(CSI(Sgr(Intensity(Bold))))
        Action(OperatingSystemCommand(FinalTermSemanticPrompt(FreshLineAndStartPrompt { aid: None, cl: None })))
        Action(Esc(Code(StringTerminator)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.03137255, 0.03137255, 0.03137255, 1.0))))))
        Print(" \u{f179} ")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Print("\u{e0b0} \u{f07c} ")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("~")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("/")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("s")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("/")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("f")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.7372549, 0.7372549, 0.7372549, 1.0))))))
        Print("/")
        Action(CSI(Sgr(Intensity(Bold))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.89411765, 0.89411765, 0.89411765, 1.0))))))
        Print("nushell")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.80784315, 0.84313726, 0.8117647, 1.0))))))
        Print(" ")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.30588236, 0.6039216, 0.023529412, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.20392157, 0.39607844, 0.6431373, 1.0))))))
        Print("\u{e0b0} ")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.30588236, 0.6039216, 0.023529412, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Print("\u{e0a0} main ")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.76862746, 0.627451, 0.0, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.30588236, 0.6039216, 0.023529412, 1.0))))))
        Print("\u{e0b0} ")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.76862746, 0.627451, 0.0, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.0, 0.0, 0.0, 1.0))))))
        Print("✚1")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Intensity(Bold))))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.76862746, 0.627451, 0.0, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.0, 0.0, 0.0, 1.0))))))
        Print("*")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.76862746, 0.627451, 0.0, 1.0))))))
        Print("\u{e0b0}")
        Action(CSI(Sgr(Reset)))
        Action(OperatingSystemCommand(FinalTermSemanticPrompt(MarkEndOfPromptAndStartOfInputUntilNextMarker)))
        Action(Esc(Code(StringTerminator)))
        Action(CSI(Sgr(Foreground(PaletteIndex(14)))))
        Action(CSI(Sgr(Intensity(Bold))))
        Print(" ")
        Action(CSI(Sgr(Foreground(PaletteIndex(5)))))
        Action(CSI(Sgr(Intensity(Bold))))
        Action(Esc(Code(DecSaveCursorPosition)))
        Action(CSI(Cursor(Position { line: OneBased { value: 24 }, col: OneBased { value: 60 } })))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.3764706, 0.3764706, 0.3764706, 1.0))))))
        Action(CSI(Sgr(Background(Default))))
        Print("\u{e0b3} 0823 ")
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.827451, 0.84313726, 0.8117647, 1.0))))))
        Print("\u{e0b2}")
        Action(CSI(Sgr(Background(TrueColor(SrgbaTuple(0.827451, 0.84313726, 0.8117647, 1.0))))))
        Action(CSI(Sgr(Foreground(TrueColor(SrgbaTuple(0.047058824, 0.047058824, 0.047058824, 1.0))))))
        Print(" 06:54:58 PM ")
        Action(CSI(Sgr(Reset)))
        Action(Esc(Code(DecRestoreCursorPosition)))
        Action(CSI(Sgr(Reset)))
        Action(CSI(Sgr(Intensity(Bold))))
        Action(CSI(Sgr(Foreground(PaletteIndex(6)))))
        Print("ls")
        Action(CSI(Sgr(Reset)))
        Print(" | ")
        Action(CSI(Sgr(Intensity(Bold))))
        Action(CSI(Sgr(Foreground(PaletteIndex(6)))))
        Print("where")
        Action(CSI(Sgr(Reset)))
        Print(" ")
        Action(CSI(Sgr(Foreground(PaletteIndex(2)))))
        Print("s")
        Action(CSI(Sgr(Reset)))
        Action(Esc(Code(DecSaveCursorPosition)))
        Action(CSI(Sgr(Foreground(PaletteIndex(8)))))
        Print("ize > 100b")
        Action(CSI(Sgr(Reset)))
        Action(Esc(Code(DecRestoreCursorPosition)))
        Action(CSI(Mode(SetDecPrivateMode(Code(ShowCursor)))))
< RECV

you can see that the stream uses cursor position escapes along with escapes to save/restore the cursor position.

@wez
Copy link

wez commented Aug 29, 2022

If I edit the macos capture and remove the OSC 133 A and OSC 133 B sequences, and replay that file on windows, then the output looks correct. Those are the FinalTerm style shell integration escape sequences.

It looks to me as though this is a ConPTY issue where unexpected/unknown OSC sequences confuse it about cursor positioning or some other similar concern that triggers it to rewrite the output stream.

A workaround would be to skip outputting OSC 133 on Windows or if you know that ConPTY is present.

@fdncred
Copy link
Collaborator

fdncred commented Aug 29, 2022

@wez That matches with what we're seeing. If people turn off shell_integration in nushell this behavior doesn't show up in WezTerm. However, if we remove OSC 133 and friends in Windows, we won't get the fancy marking in Windows Terminal Preview nor in VSCode's terminal. I'm going to link your speculation to the Windows Terminal issue to see if it helps. I think this issue and the WT issue are related since the problem in both terminals started happening with the OSC 133 sequences.

@kaifastromai
Copy link

Just wanted to chime in to confirm I still get this with v 0.78.0 of nushell and wezterm 20230408 (69ae472)

@valerii15298
Copy link

Is it possible for now to disable shell_integration in Nushell only when it is running inside Wezterm? Because it is the only terminal emulator I have a problem with.

@nerditation
Copy link

Is it possible for now to disable shell_integration in Nushell only when it is running inside Wezterm? Because it is the only terminal emulator I have a problem with.

well, I know wezterm will set certain environment variables prefixed with WEZTERM_ such as WEZTERM_EXECUTABLE, WEZTERM_PANE, etc. but I don't know the syntax of the nu script. I think it's possible in the config.nu script to conditionally set shell_integration based on whether certain environment variable is defined or not.

@okmanideep
Copy link

Linked issue of microsoft/terminal has been fixed - microsoft/terminal#13710

@fdncred
Copy link
Collaborator

fdncred commented May 12, 2023

anyone built windows terminal to see if it's fixed? i'm not brave enough right now. hopefully we'll get a new WT version soon.

@kvnxiao
Copy link

kvnxiao commented Jun 4, 2023

Is it possible for now to disable shell_integration in Nushell only when it is running inside Wezterm? Because it is the only terminal emulator I have a problem with.

well, I know wezterm will set certain environment variables prefixed with WEZTERM_ such as WEZTERM_EXECUTABLE, WEZTERM_PANE, etc. but I don't know the syntax of the nu script. I think it's possible in the config.nu script to conditionally set shell_integration based on whether certain environment variable is defined or not.

One way to do this is to edit config.nu and set shell_integration line to:

shell_integration: ("WEZTERM_PANE" not-in $env)

So that shell_integration is disabled when nushell is loaded by WezTerm.

@wez
Copy link

wez commented Jun 4, 2023

I wanted to note that wezterm's nightly build has included the upstream conpty fixes for the past week or so.

@CGMossa
Copy link
Author

CGMossa commented Jun 4, 2023 via email

@fdncred
Copy link
Collaborator

fdncred commented Jun 4, 2023

I wanted to note that wezterm's nightly build has included the upstream conpty fixes for the past week or so.

@wez I tested your upstream fixes and tagged you in my testing report on the WT thread. WezTerm still looked broken to me but in a slightly different way.

@sholderbach sholderbach added line editor Issues related to reedline and removed Stale used for marking issues and prs as stale labels Jul 6, 2023
@okmanideep
Copy link

0.82 still had this issue. But 0.84 doesn't seem to have it 🙌

I think I can finally switch to nushell!
the-its

@CGMossa CGMossa closed this as completed Aug 26, 2023
@fdncred fdncred reopened this Aug 28, 2023
@fdncred
Copy link
Collaborator

fdncred commented Aug 28, 2023

I don't believe this issue is fixed. It's just that we changed the default of $env.config.shell_integration to false instead of true. I still see the same duplication on the command line for every character typed.

This is from 20230712-072601-f4abf8fd
wezterm

@nerditation
Copy link

I don't believe this issue is fixed. It's just that we changed the default of $env.config.shell_integration to false

I think the root cause has not been precisely indentified. I would guess it's likely due to quirks in the windows pseudo terminal API implementation, as this behavior doesn't only show up for wezterm, but some other terminal emulators on windows too.

that being said, there's almost certainly something unusual in nu's hanlding of control sequence escape codes. I recently observed a (likely) related but not identical behavior in the winpty terminal emulator (mind you, it is a third party terminal emulator, not Windows' builtin conpty ) inside the integrated terminal of vscode.

this behavior is very strange, but I think it might be related to this issue, so I'll describe it here in case it might help to locate the root cause of the problem.

initially, the shell seems work normally, but after several commands, once the screen begins to scroll up, then each key stroke will make the screen scroll one line.

please note, I have set nu.config.shell_integration to false already, but problem appears when I set vscode's terminal.integrated.windowsEnableConpty to false.

@fdncred
Copy link
Collaborator

fdncred commented Jan 18, 2024

My guess for this has always been that reedline is redrawing the prompt on every keystroke. I think this could be something that was left behind when we had a ticking clock as a prompt. It's kind of tricky to diagnose and fix but I'm hoping someone will dig in and figure it out.

@dan-myles
Copy link

Hey, just commenting here to come and say that I have the same issue that OP is talking about and it is still happening even on a nightly version of wezterm. Thanks!

@mtuckerb
Copy link

Are you sometimes —but not when this duplication error is happening — using tmux? Does it echo normally when using tmux?

@dan-myles
Copy link

Are you sometimes —but not when this duplication error is happening — using tmux? Does it echo normally when using tmux?

Unfortunately I am not tmux, since I am on windows. So this is just normal wezterm.

@cbr9
Copy link

cbr9 commented May 30, 2024

Hi

It seems that changing shell_integration.osc133 to false fixes the problem for me, as such

 shell_integration: {
        # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title
        osc2: true
        # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory
        osc7: true
        # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it. show_clickable_links is deprecated in favor of osc8
        osc8: true
        # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal
        osc9_9: true
        # osc133 is several escapes invented by Final Term which include the supported ones below.
        # 133;A - Mark prompt start
        # 133;B - Mark prompt end
        # 133;C - Mark pre-execution
        # 133;D;exit - Mark execution finished with exit code
        # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is
        osc133: false
        # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features
        # 633;A - Mark prompt start
        # 633;B - Mark prompt end
        # 633;C - Mark pre-execution
        # 633;D;exit - Mark execution finished with exit code
        # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce
        # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal
        # and also helps with the run recent menu in vscode
        osc633: true
        # reset_application_mode is escape \x1b[?1l and was added to help ssh work better
        reset_application_mode: true
    }

ErichDonGubler added a commit to erichdongubler-dotfiles/nushell that referenced this issue Jun 17, 2024
@tgross35
Copy link

This might be a duplicate of #10671 (for which making osc133 false also fixes it)

@kmoschcau
Copy link

Hi, I'm currently trying out nushell and I am also running into this problem. Not only does previous output scroll up one line on each character modified in the input line, but also when navigating around in the input line. Just pressing the left and right arrows is enough, even on an empty line.

However I have a hunch what the reason might be: Nushell's prompt emits OSC 133;A somewhere in the prompt, but not in the first column. This causes wezterm to insert a newline on each redraw.

Some context: I also only recently started trying out nushell and wezterm. My previous shell is fish with vi key bindings and I manually added the OSC 133 escape sequences to my prompt. This worked fine with other terminals for years, both on Linux and WSL on Windows.
When I tried this setup in wezterm, I suddenly started seeing a line break in my prompt after the vi mode indicator. The reason was, that I emitted the the OSC 133;A as the first thing of the normal prompt, but after the vi mode indicator, so not on the first column. Looking at the proposed spec for those escape sequences, OSC 133;A does a "fresh-line" (OSC 133;L) implicitly. Meaning the terminal emulator should render a new line, when this escape sequence is emitted anywhere but the first column. When I changed my fish prompt to emit OSC 133;A only in the first column, the problem went away. Wezterm is the only terminal emulator I have encountered so far that does this newline behavior. I did not see those newlines with my fish prompt in other terminal emulators neither on Linux nor on Windows.

@fdncred
Copy link
Collaborator

fdncred commented Oct 8, 2024

Thanks for the advice @kmoschcau. I'll look into your findings to see if we can somehow do that for nushell too. For now, if you turn off osc133 in your config, the problem should go away.

@fdncred
Copy link
Collaborator

fdncred commented Oct 8, 2024

From what I can tell OSC 133;A is the first character on the line but it's repeated a few times for some reason.
image

@fdncred
Copy link
Collaborator

fdncred commented Oct 8, 2024

I definitely think something strange is going on with WezTerm. Both these tests did the same thing which is cargo run and then hit enter.

Windows Terminal

image

WezTerm

image

@kmoschcau
Copy link

Sure wezterm is the only one I have seen so far that is adhering to the spec so strictly. But nushell is also the only shell that I tried, which provokes this behavior in WezTerm. Neither powershell nor fish do this. Granted, I emit OSC 133;A manually for both of these in the first column. I also just did a test with my powershell config and emitted an additional OSC 133;A in the middle of the prompt, which also gave me the broken rendering. Though I can't replicate the the behavior that previous lines scroll up like in nushell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
line editor Issues related to reedline upstream problem with upstream dependency
Projects
None yet
Development

No branches or pull requests