Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15638

[readline] Multibyte invisible chars cause weird prompt length calculation issue

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Алексей Шилин <rootlexx@mail.ru>
Newsgroups gnu.bash.bug
Subject [readline] Multibyte invisible chars cause weird prompt length calculation issue
Date Mon, 25 Nov 2019 18:05:21 +0300
Lines 83
Approved bug-bash@gnu.org
Message-ID <mailman.2595.1574696278.13325.bug-bash@gnu.org> (permalink)
References <3dd641953467a3299265e479026fc40a7bb697d4.camel@mail.ru>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8bit
X-Trace usenet.stanford.edu 1574696279 5696 209.51.188.17 (25 Nov 2019 15:37:59 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Content-Transfer-Encoding:MIME-Version:Content-Type:Date:To:From:Subject:Message-ID; bh=TQbyOTaUkiQ6vtX96d/i4G275Vaa1HQZojdATQVFOgg=; b=klWeExmtvaaVAM2he5vo29vKGeZeJ3Bbhe5xyxwYgKgdr6OkCaakl6o9LtAglks3XYC3eb6tx4PvyPjWP+1sD6/BSvgTiPRirMJgoVkkSQyjyWGsZr9m/PAdKpSn2+j/pN26SVlF8UWWGNzxaxQ7rbb5mhwr2AwrHyNc5y1eXA4=;
User-Agent Evolution 3.30.5-1.1
Authentication-Results smtp52.i.mail.ru; auth=pass smtp.auth=rootlexx@mail.ru smtp.mailfrom=rootlexx@mail.ru
X-77F55803 260C666A7D66B36A5A78504BD2AC29411FA4F02123E218F92D6A137B11F86B4376BAE103D741C2BEF700848E1018E217
X-7FA49CB5 FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B72EF797F6622CCCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CFE0CC87CA3F0D618638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC5A25DE20BCC2678E78F3F1AC97FDF0B6CA0D0FE7CBCB4A26389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0E7DDDDC251EA7DABA471835C12D1D977725E5C173C3A84C3ED8438A78DFE0A9E117882F4460429728AD0CFFFB425014E40A5AABA2AD371193AA81AA40904B5D9A18204E546F3947CEB7D890E3377C531040F9FF01DFDA4A84AD6D5ED66289B52E1A3F18E62937ED6A8C29749A63C2581725E5C173C3A84C3E3BB2FD1E47095BBBA3038C0950A5D36B5C8C57E37DE458B5A02E28F51ECAD4422CA9DD8327EE4930A3850AC1BE2E73591D3EDA82B9DE789A35E28386C4E1F61731C566533BA786A40A5AABA2AD371193C9F3DD0FB1AF5EB38286209DE2710BF3C9F3DD0FB1AF5EB4E70A05D1297E1BBCB5012B2E24CD356
X-Mailru-Sender FD65D7C492470CAED3DD1703795F7E025CB15DE8F8664A22E2009B310D3E11693DCE99E73093D3FC15D893B5EE9B869EC77752E0C033A69ED2A0601D20520849A97B7613133B5FEC3453F38A29522196
X-Mras OK
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 94.100.177.112
X-Mailman-Approved-At Mon, 25 Nov 2019 10:37:57 -0500
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <3dd641953467a3299265e479026fc40a7bb697d4.camel@mail.ru>
Xref csiph.com gnu.bash.bug:15638

Show key headers only | View raw


Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-REtn6r/bash-
5.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux sid-readline 4.19.0-6-amd64 #1 SMP Debian 4.19.67-
2+deb10u2 (2019-11-11) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 11
Release Status: release

Description:

I'm using the following PS1 prompt (Debian's default for normal users):

\[\e]0;\u@\h:
\w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\
]:\[\033[01;34m\]\w\[\033[00m\]\$ 

...where the first block '\[\e]0;\u@\h: \w\a\]' is for setting xterm's
title, and the rest is Debian's "fancy" shell prompt.

The issue is, when \w contains multibyte characters (e.g. Cyrillic),
some weird prompt length calculation issues start happening (see
below).

Repeat-By:

test@sid-readline:~$ PS1='\[\e]0;\u@\h:
\w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\
]:\[\033[01;34m\]\w\[\033[00m\]\$ '
test@sid-readline:~$ mkdir -p тестовый/каталог
test@sid-readline:~$ cd тестовый/каталог/
test@sid-readline:~/тестовый/каталог$ echo hello cruel world
hello cruel world
test@sid-readline:~/тестовый/каталог$ 

# Press C-r for history backward search:

(reverse-i-search)`':стовый/каталог$ 

                      ^----- cursor is here

# Note that part of the previous prompt is still visible.
# Enter 'he':

(reverse-i-search)`he': echo hello cruel world

# ...and press [ End ]:

test@sid-readline:~/тестовый/каталог$ l world               

                                        cursor is here -----^

# As you see, the command line is shifted to the left by the same 
# number of chars as the amount of "extra" bytes in \w.

# Now let's delete \w from the *first* ("xterm's") invisible 
# characters block:

test@sid-readline:~/тестовый/каталог$ PS1='\[\e]0;\u@\h:
\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:
\[\033[01;34m\]\w\[\033[00m\]\$ '
test@sid-readline:~/тестовый/каталог$ 

# Press C-r again:

(reverse-i-search)`': 

# Now there's no junk left in the prompt line.
# Enter 'he' again and press [ End ]:

test@sid-readline:~/тестовый/каталог$ echo hello cruel world

# As you see, now everything works as expected i.e. the issue seems
# to be in the way readline is handling multibyte invisible characters 
# in a prompt, *probably* in the rl_redisplay() function.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

[readline] Multibyte invisible chars cause weird prompt length calculation issue Алексей Шилин <rootlexx@mail.ru> - 2019-11-25 18:05 +0300

csiph-web