代码之家  ›  专栏  ›  技术社区  ›  Sergiy Belozorov Mohaiminul Islam

zsh中的PS1配置会在每次提示重新绘制后删除前一行

  •  0
  • Sergiy Belozorov Mohaiminul Islam  · 技术社区  · 10 年前

    我的 .zsh config包含以下行:

    function zle-line-init zle-keymap-select {
        VIM_PROMPT="${${KEYMAP/vicmd/ [NORMAL]}/(main|viins)/}"
        PS1=$'\e[0;36m%n\e[m at \e[0;33m%m\e[m in \e[0;32m%~\e[m\e[0;34m$(vcs_info_wrapper)\e[m\e[1;33m$VIM_PROMPT\e[m\n$ '
        zle reset-prompt
    }
    

    如果终端窗口太窄,则每次重新绘制提示时,前一行都会被删除。例如,假设我有以下提示:

    first line
    some text here
    another text here
    sergiyb at wing in ~ [master *]
    $ 
    

    逃跑 得到

    first line
    some text here
    sergiyb at wing in ~ [master *] [NORMAL]
    $ 
    

    我 然后我就明白了

    first line
    sergiyb at wing in ~ [master *]
    $ 
    

    类似地,如果我输入命令 ls ,它列出所有文件,但删除最后一行:

    sergiyb at wing in ~ [master *]
    $ ls test_dir_with_files_1_to_10
    file1   file2  file4  file6  file8
    

    然而,如果终端窗口足够宽,则不会发生这种情况,例如:。

    sergiyb at wing in ~ [master *]
    $ ls test_dir_with_files_1_to_10
    file1  file10  file2  file3  file4  file5  file6  file7  file8  file9
    

    此外,如果我试图缩短我的PS1行,例如删除用户名,那么它将停止发生,直到我进一步减小终端的宽度。

    您知道是什么原因导致了这种情况和/或如何解决?

    1 回复  |  直到 10 年前
        1
  •  2
  •   chepner    10 年前

    zsh 无法准确确定提示的大小,因为它不知道终端不将ANSI转义码显示为可打印字符。使用 zsh 而是它自己的格式和转义。

    PS1=$'%F{cyan}%n%f at %F{yellow}%m%f in %F{green}%~%F{blue}$(vcs_info_wrapper)%B%F{yellow}$VIM_PROMPT%f%b\n$ '