简体   繁体   English

Powerline PS1换行

[英]Powerline PS1 line wrapping

Context 语境

Powerline installed from arch linux packages, not from pip. 电力线是从arch linux软件包而不是pip安装的。

PS1 Script PS1脚本

update-ps() {
    export PS1="$(powerline shell aboveleft)"
    export PS2="$(powerline shell left)"
}

export PROMPT_COMMAND="update-ps;$PROMPT_COMMAND"

Powerline config 电力线配置


Problem 问题

I have the same problem as him , when I write a few chars the line wraps and I start writing in the same line, overwriting what I already wrote (including ps1). 我和有同样的问题,当我写几个字符时,换行并且开始在同一行写,覆盖了我已经写过的内容(包括ps1)。

I am aware that this could be a non-printable character problem, but doesn't it means that it's a powerline bug? 我知道这可能是无法打印的字符问题,但这不是说这是电力线错误吗? What other problems can it be? 还有什么其他问题?

This can occur when the locale is incorrect, or when glibc is built with "C" locale, which does not support unicode characters. 当语言环境不正确时,或者使用不支持Unicode字符的“ C”语言环境构建glibc时,可能会发生这种情况。 Powerline uses non-breaking spaces (2-byte) and also uses 2-byte unicode characters for the triangles. Powerline使用不间断空格(2字节),并且对三角形也使用2字节unicode字符。 For each one of these characters, the shell (not powerline) thinks that 1 extra character has been printed. 对于这些字符中的每个字符,外壳程序(不是电源线)都认为已打印了一个额外的字符。 If you have 5 spaces and 3 triangles in the prompt, then the prompt will wrap 8 characters before it hits the end of the line. 如果提示中有5个空格和3个三角形,则提示在到达行尾之前将自动换行8个字符。 From there everything behaves incorrectly. 从那里开始,一切都不正常。 This only relates to Powerline in the sense that Powerline uses unicode characters in the prompt. 仅在Powerline在提示中使用Unicode字符的意义上,这才与Powerline有关。

The fix is to correct the locale so the shell understands 2-byte unicode. 解决方法是更正语言环境,以便外壳程序可以理解2字节的unicode。 You can run "locale" to see if the shell is using "C", in which case it needs to be fixed. 您可以运行“ locale”来查看外壳是否使用“ C”,在这种情况下,需要对其进行修复。 For my application, we were running Powerline in a Docker image running Centos Linux. 对于我的应用程序,我们在运行Centos Linux的Docker映像中运行Powerline。 We had to fix the locale in /etc/yum.conf to use the lowercase form of utf8 like so: 我们必须修复/etc/yum.conf中的语言环境,以使用utf8的小写形式,如下所示:

sed -i 's/UTF-8/utf8/' /etc/yum.conf

Then rebuild glibc-common with the fix: 然后使用修复程序重建glibc-common:

yum reinstall glibc-common

After that, new terminals behaved and the prompt wrapped correctly. 之后,新的终端运行正常,提示正确包装。 We then modified our Docker image to fix yum.conf before installing glibc. 然后,在安装glibc之前,我们修改了Docker映像以修复yum.conf。 However, we found one of our modules was changing the locale back to C (LANG="C"), so we used the LC_ALL env var to override it: 但是,我们发现其中一个模块正在将语言环境改回C(LANG =“ C”),因此我们使用LC_ALL env var覆盖了它:

LC_ALL=en_US.UTF_8

After that, all new terminals behaved correctly. 之后,所有新终端均正常运行。

For me changing in ~.bashrc: from: 对我来说〜.bashrc中的更改:从:

. /usr/local/lib/python2.7/dist-packages/powerline/bindings/shell/powerline.sh

to

. /usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh

resolved the issue 解决了问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM