nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
517 stars 140 forks source link

Nushell: Multi-line Prompt Bug When Resizing Window #809

Open NOname-awa opened 1 month ago

NOname-awa commented 1 month ago

Describe the bug

When using Nushell with a multi-line prompt, resizing the terminal window causes a display issue. Specifically, after resizing the terminal window, any subsequent input results in the new prompt overlapping with the previous prompt.

┌  NU▕ noname-awa  ~ 
└ > enter pro

┌  NU▕ noname-awa  №1  ~  pro   master 
└ > # Normal input

┌  NU▕ noname-awa  №1  ~  pro   master 

┌  NU▕ noname-awa  №1  ~  pro   master 

┌  NU▕ noname-awa  №1  ~  pro   master 
└ > # Resize the terminal before entering

┌  NU▕ noname-awa  №1  ~  pro   master 
└ >

How to reproduce

Expected behavior

After resizing, the prompt does not experience the “overlap” issue.

Like ↓

┌  NU▕ noname-awa  ~ 
└ > enter pro

┌  NU▕ noname-awa  №1  ~  pro   master 
└ > # Normal input

┌  NU▕ noname-awa  №1  ~  pro   master 
└ > # Resize the terminal before entering

┌  NU▕ noname-awa  №1  ~  pro   master 
└ >

Screenshots

圖片

Configuration

key value
version 0.95.0
major 0
minor 95
patch 0
branch
commit_hash f93c6680bd5ae158190556eb1afc924b0290b52f
build_os linux-x86_64
build_target x86_64-unknown-linux-musl
rust_version rustc 1.77.2 (25ef9e3d8 2024-04-09)
rust_channel 1.77.2-x86_64-unknown-linux-gnu
cargo_version cargo 1.77.2 (e52e36006 2024-03-26)
build_time 2024-06-25 18:39:03 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, static-link-openssl, system-clipboard, trash
installed_plugins

Additional context

My theme (config.nu)

$env.STARSHIP_SHELL = "nu"

let black_fg = "\e[30m"
let black_bg = "\e[40m"
let blue_fg = "\e[38;2;129;169;254m"
let blue_bg = "\e[48;2;129;169;254m"
let dark_blue_fg = "\e[38;2;59;66;97m"
let dark_blue_bg = "\e[48;2;59;66;97m"
let pink_fg = "\e[38;2;197;134;192m"
let bold = "\e[1m"
let reset = "\e[0m"

let user = $env.USER

def format-path [path: string] {
    if $path == "/" {
        "/"
    } else {
        let home = $env.HOME
        let relative_path = ($path | str replace $home "~")

        let path_parts = ($relative_path | split row "/")

        let path_parts_count = ($path_parts | length)

        if $path_parts_count < 2 {
            $relative_path
        } else {
            let abbreviated_parts = ($path_parts | each {|part| 
                if $part in ($path_parts | skip ($path_parts_count - 2)) {
                    $part
                } else {
                    ($part | str substring 0..0)
                }
            })

            let formatted_path = ($abbreviated_parts | str join ($" ($black_fg)" + "" + $"($blue_fg) "))

            if ($relative_path | str starts-with "/") {
                "/" + $formatted_path
            } else {
                $formatted_path
            }
        }
    }
}

def get-git-info [] {
    if (git rev-parse --is-inside-work-tree err> /dev/null) == "true" {
        let branch = (git symbolic-ref --short HEAD err> /dev/null)
        if ($branch != "") {
            $branch
        } else {
            ""
        }
    } else {
        ""
    }
}

def getshells [] {
    let shells = ((shells | enumerate | where $it.item.active == true).0.index err> /dev/null)
    if (shells | length) > 1 {
        $" ($dark_blue_bg + $blue_fg) №($shells)"
    } else {
        ""
    }
}

def create_prompt [] {
    let path = (format-path (pwd))
    let git_info = (get-git-info)
    let shells_info = (getshells)

    mut prompt = $"($reset)\n┌ "
    $prompt += $"($blue_fg)($reset)"
    $prompt += $"($blue_bg + $black_fg) NU▕ ($user + $shells_info) ($reset)"
    $prompt += $"($black_bg + if $shells_info != "" { $dark_blue_fg } else { $blue_fg })($reset)"
    $prompt += $"($dark_blue_bg + $black_fg)"
    $prompt += $"($dark_blue_bg + $blue_fg) ($path) ($reset)"
    $prompt += $"($dark_blue_fg)($reset)"

    if $git_info != "" {
        $prompt += $" ($pink_fg) ($git_info)($reset)"
        if $env.LAST_EXIT_CODE == 0 {
            $prompt += " "
        }
    }

    if $env.LAST_EXIT_CODE != 0 {
        $prompt += $"($bold + $dark_blue_fg) ($env.LAST_EXIT_CODE) ($reset)"
    }

    $prompt += $"($blue_fg)($reset)"

    $prompt
}

$env.PROMPT_COMMAND = { create_prompt }
$env.PROMPT_COMMAND_RIGHT = ""

$env.PROMPT_INDICATOR = $reset + "\n└ > "
$env.PROMPT_MULTILINE_INDICATOR = "┆ - "
fdncred commented 1 month ago

Agreed. This is a known issue with reedline. I'm sure there are probably issues logged here and in the reedline repo.

ArtemChandragupta commented 1 month ago

https://github.com/user-attachments/assets/2c243a59-a562-42bd-ba0b-c100a7240cfb

Video demonstrating this effect