nushell icon indicating copy to clipboard operation
nushell copied to clipboard

significant flickering with nushell on windows using oh-my.nu

Open fdncred opened this issue 2 years ago • 15 comments

Describe the bug

with every character typed the screen flickers see gifs below. it works fine in 0.65.0.

git bisect says 98126e298175ed78a5797bacc06d0704a30b1785 is the first bad commit

I don't really understand what is going on and why this PR is causing issues.

How to reproduce

run nushell on windows terminal with oh-my.nu custom prompt. it may happen with other prompts too, i'm not sure. i'm also not sure if it happens on other operating systems. i haven't noticed it on my mac but maybe redraw/flicker is so fast i don't see it.

Expected behavior

no flickering

Screenshots

both these gifs demonstrate the flicker/redraw/blink but they don't capture it perfectly. it flickers on every keystroke. the gifs miss some flickers. flicker1 flicker2 In WezTerm it's horrendous and redraws the prompt on every single character flicker3

Configuration

key value
version 0.66.3
branch
commit_hash 56069af42d2b62b594d88668a1ce85a8697b58e6
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.62.0 (a8314ef7d 2022-06-27)
rust_channel stable-x86_64-pc-windows-msvc
cargo_version cargo 1.62.0 (a748cf5a3 2022-06-08)
pkg_version 0.66.3
build_time 2022-08-02 10:22:29 -05:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins gstat, inc, nu-example-1, nu-example-2, nu-example-3, query, query json, query web, query xml

Additional context

No response

fdncred avatar Aug 02 '22 16:08 fdncred

I've tracked it down to this https://github.com/nushell/nushell/blob/233afebdf0bf4df9fedd8232da93c963ae91bc19/crates/nu-cli/src/prompt_update.rs#L97-L117. Unfortunately, I'm not sure how to proceed from here because any modification of left_prompt_string causes flickering. The only other idea I have is exposing the string from reedline for manipulation but I'm open to ideas.

fdncred avatar Aug 02 '22 19:08 fdncred

I give up on this. 😭 I've tried 5 or so ways to try and prevent this flickering by moving this shell integration settings around but every time the prompt is updated flicker occurs. I've even tried augmenting the reedline trait so that in the repl.rs i can update the left prompt string, after the prompt is initially set but it resulted in the same flickering.

The flicker is super aggravating but apparently no one else on windows uses a heavily customized prompt. So, i'll have to wait until someone care enough and is smart enough to fix it. :)

fdncred avatar Aug 03 '22 16:08 fdncred

Update: This is reproduceable with the prompt in our default_env.nu (below) so it's not related to my prompt script. It's related to every custom prompt.

def create_left_prompt [] {
    let path_segment = if (is-admin) {
        $"(ansi red_bold)($env.PWD)"
    } else {
        $"(ansi green_bold)($env.PWD)"
    }

    $path_segment
}

def create_right_prompt [] {
    let time_segment = ([
        (date now | date format '%m/%d/%Y %r')
    ] | str collect)

    $time_segment
}

# Use nushell functions to define your right and left prompt
let-env PROMPT_COMMAND = { create_left_prompt }
let-env PROMPT_COMMAND_RIGHT = { create_right_prompt }

fdncred avatar Aug 05 '22 13:08 fdncred

I'm noticing flicker when typing too (mostly default config, Windows Terminal, Nu running on both Windows+WSL). I did a git bisect and it seems like the VS Code changes (#6087) are the culprit.

edit: I need to read before investigating things, I noticed that you also pinpointed the exact PR. My bad 😅

rgwood avatar Aug 08 '22 00:08 rgwood

LOL. Yes, flickering on Windows is horrible. I can't figure it out. My guess is that it's not this PR directly because it's silly that this code change would cause a flicker for each character you type. I think this PR is a symptom, not the problem.

fdncred avatar Aug 08 '22 01:08 fdncred

@fdncred figured out that this is only happening in Windows Terminal Preview v1.15 (thanks!).

In Preview v1.15 they added experimental scroll mark support, which is also the subject of #6087 so... there must be some bad interaction between our scroll mark output and WT.

Disabling scroll mark support in WT doesn't fix the issue, unfortunately.

rgwood avatar Aug 08 '22 15:08 rgwood

@rgwood Do you think we should add an issue on the WT repo?

fdncred avatar Aug 08 '22 16:08 fdncred

Yes I think that would be a good idea.

If you have time now, great; if not I can file an issue tonight or tomorrow.

rgwood avatar Aug 08 '22 16:08 rgwood

@rgwood Would you mind doing it please, whenever you can get to it? Just ping me here with the issue number so i can subscribe to it.

fdncred avatar Aug 08 '22 17:08 fdncred

@fdncred Filed: https://github.com/microsoft/terminal/issues/13710

rgwood avatar Aug 09 '22 18:08 rgwood

Setting "shell_integration: false" in config.nu fixes the problem

micgao avatar Aug 25 '22 07:08 micgao

Setting "shell_integration: false" in config.nu fixes the problem

@micgao correct. that's why I listed the commit that added that feature when I created this issue. disabling that feature is not a "fix".

fdncred avatar Aug 28 '22 12:08 fdncred

commenting just to say that this also happens on WT Preview 1.16.2641.0, with nushell downloaded as-is from winget and the default config file. For any other beginners that (like me) stumble upon this issue as soon as they install nu: it's sufficient to comment the first section, up until let-env PROMPT_COMMAND_RIGHT = ... (for me, that's lines 3 to 23), in the file %appdata%/nushell/env.nu and the flickering completely stops.

NSilv avatar Nov 03 '22 08:11 NSilv

I still get flicker in wt and wtp, even if the right prompt is removed. The only thing I've found to resolve it with custom prompts is this let-env config = ($env.config | upsert shell_integration false)

fdncred avatar Nov 03 '22 13:11 fdncred

Nu users: if this bothers you please upvote the Windows Terminal issue

rgwood avatar Nov 03 '22 15:11 rgwood

Setting "shell_integration: false" in config.nu fixes the problem

Thanks, that's worked for me 🙇‍♂️

andrei-hernandez avatar Jan 08 '23 00:01 andrei-hernandez

This problem is still there as of today. That said, setting "shell_integration: false" in config.nu did fix the flickering problem.

g-berthiaume avatar Jun 15 '23 13:06 g-berthiaume

@g-berthiaume The issue is gone in the latest Windows Terminal Preview v1.18.1462

fdncred avatar Jun 15 '23 16:06 fdncred

Ok thanks for the update.

g-berthiaume avatar Jun 16 '23 12:06 g-berthiaume

So BTW, whatever causes this in Windows terminal also makes WezTerm do something weird, whenever I type a key it's adding a newline to my terminal output, thus pushing any content above the prompt upwards.

bartdorsey avatar Jul 06 '23 02:07 bartdorsey

Setting shell_integration false fixes WezTerm as well.

bartdorsey avatar Jul 06 '23 02:07 bartdorsey

@bartdorsey Yup, Wez was working on that last I checked. Trying to use the conpty that WT uses or something like that. https://github.com/nushell/nushell/issues/5585

fdncred avatar Jul 06 '23 12:07 fdncred

I get this in ConEmu despite shell_integration being set to false in my config.nu. It doesn't seem to happen when the terminal is clear (i.e. the prompt is at the top of the window), but when I've issued a few commands and the prompt is about halfway down the window, it starts to flicker as I'm typing.

drguildo avatar Jan 27 '24 11:01 drguildo

I think the root of this problem is that nushell/reedline redraws the prompt with every character typed. If you have a fast system and a fast terminal, it's not very noticeable. We'd love for someone to dig in and fix it in reedline.

However, this issue should be closed because it was specifically about Windows Terminal and that is fixed.

fdncred avatar Jan 27 '24 13:01 fdncred

If this is an example of a broader issue, then please redirect it to that GitHub issue.

drguildo avatar Jan 27 '24 21:01 drguildo