Bug 231405 - Setting terminal title - ANSI string terminator not supported
Summary: Setting terminal title - ANSI string terminator not supported
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: emulation (show other bugs)
Version: 17.12.3
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-20 12:25 UTC by Mantas Mikulėnas
Modified: 2020-01-03 15:49 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In: 19.12.0


Attachments
untested patch (566 bytes, patch)
2014-06-28 15:24 UTC, Martin Sandsmark
Details
Followup fix (1.44 KB, patch)
2018-09-30 11:21 UTC, Egmont Koblinger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mantas Mikulėnas 2010-03-20 12:25:17 UTC
Version:           2.4.1 (using KDE 4.4.1)
OS:                Linux
Installed from:    Archlinux Packages

TL;DR summary: Konsole should treat "\e]0;<title>\e\\" (set window title) the same way it interprets "\e]0;<title>\007".


I have this string as part of my $PS1 ('bash' prompt string):

    \e]0;<title>\e\\
    
This is supposed to set the window title in Xterm-compatible terminal emulators. However, Konsole 2.4.1 (KDE 4.4.1) does not support this and reports an error:

    Undecodable sequence: \001b(hex)\\

It seems that Konsole does not recognize the standard string terminator sequence "\e\\" (ESC \). Everything works fine if I use "\007" (BEL) as string terminator, but I would prefer to use the standard one.

According to <http://invisible-island.net/xterm/xterm.faq.html#how2_title>:

# The terminator "\007" is a problem area. Xterm historically uses this character, though it is non-ANSI. The "correct" character should be a "\233" string terminator, or "\033\\", which is the 7-bit equivalent. XFree86 xterm recognizes either (the "\007" or string terminator); waiting for the first of these.

Most other terminal emulators also accept both "\007" and "\033\\" - I tested VTE-based ones qw[roxterm xfce4-terminal gnome-terminal], rxvt, and PuTTY. Konsole is the only one so far that requires "\007".
Comment 1 Martin Sandsmark 2014-06-28 15:24:03 UTC
Created attachment 87450 [details]
untested patch

haven't tested this, but I think it should fix it.
Comment 2 Kurt Hindenburg 2017-01-28 15:27:02 UTC
Git commit 5601e995bd8715ea9e186e447a947cd48736bfee by Kurt Hindenburg.
Committed on 28/01/2017 at 15:22.
Pushed by hindenburg into branch 'master'.

Allow ANSI string terminator to work

Treat "\e]0;<title>\e\\" (set window title) the same way
it interprets "\e]0;<title>\007".

It seems that Konsole does not recognize the standard string terminator
sequence "\e\\" (ESC \). Everything works fine if I use "\007" (BEL).

<http://invisible-island.net/xterm/xterm.faq.html#how2_title>

Thanks to Aniketh Girish anikethgireesh gmail com and Martin Sandsmark
martin sandsmark kde org for patch/review
REVIEW:129895

M  +1    -1    src/Vt102Emulation.cpp

https://commits.kde.org/konsole/5601e995bd8715ea9e186e447a947cd48736bfee
Comment 3 Grey Em 2017-04-25 02:24:50 UTC
Bug was not totally fixed with this patch, and introduced a different bug. The patch (which is now released) compares the character against decimal 33, which is actually !, not ESC. This creates a bug where if a ! appears in the terminal title, it's treated as the end of the title, and the rest of the title (including the ESC or BEL) is printed normally. Comparing against octal 033 or decimal 27 will properly detect ESC.
Comment 4 Kurt Hindenburg 2017-04-25 03:01:03 UTC
Thanks - I wonder how my testing got this to work
Comment 5 Kurt Hindenburg 2017-05-05 12:12:00 UTC
Git commit 7a41b73b46d1f774e82eb64a8b66920e411ccd3c by Kurt Hindenburg.
Committed on 05/05/2017 at 12:11.
Pushed by hindenburg into branch 'master'.

Correct ANSI string terminator

Use the correct decimal value 27

In bash, PS1="\e]0;<title>\e\\" or PS1="\e]0;<title>\033"

Differential Revision: https://phabricator.kde.org/D5576

M  +1    -1    src/Vt102Emulation.cpp

https://commits.kde.org/konsole/7a41b73b46d1f774e82eb64a8b66920e411ccd3c
Comment 6 Kurt Hindenburg 2017-05-07 13:55:21 UTC
Git commit 355ca4063ced46ea990e68e5abdda62826386f2c by Kurt Hindenburg.
Committed on 07/05/2017 at 13:46.
Pushed by hindenburg into branch 'Applications/17.04'.

Correct ANSI string terminator

Use the correct decimal value 27

In bash, PS1="\e]0;<title>\e\\" or PS1="\e]0;<title>\033"

Differential Revision: https://phabricator.kde.org/D5576

(cherry picked from commit 7a41b73b46d1f774e82eb64a8b66920e411ccd3c)

M  +1    -1    src/Vt102Emulation.cpp

https://commits.kde.org/konsole/355ca4063ced46ea990e68e5abdda62826386f2c
Comment 7 Egmont Koblinger 2018-09-11 09:50:08 UTC
Reopening, it's not okay in 17.12.3.

The command:

    echo -e '\e]0;Title\e\\'

not only sets the title, but also emits a literal backslash.

(On a side note, there seems to be a buffer corrpution bug in bash-4.4, causing the particular PS1 that you've mentioned earlier to emit garbage in other terminals too. So don't use PS1 for debugging/verifying this issue :))
Comment 8 Egmont Koblinger 2018-09-30 11:21:53 UTC
Created attachment 115326 [details]
Followup fix

Followup fix for the erroneously emitted literal backslash.

Works for me.

Please test thoroughly and adjust to konsole's coding practices or whatever.
Comment 9 Kurt Hindenburg 2019-11-02 16:10:33 UTC
Git commit 324d78c07fc4fe2cdb2219a9e042a969df73d39c by Kurt Hindenburg, on behalf of Mariusz Glebocki.
Committed on 02/11/2019 at 16:01.
Pushed by hindenburg into branch 'master'.

Fix OSC sequence parsing

printf '\033]2;aaa\033bbb' prints bbb
printf '\033]2;aaa\033\\bbb' prints bbb
printf '\033]2;aaa\033' prints nothing;
        title is changed when next character is received.
printf '\033]2;aaa\033\\' prints nothing
printf '\033]2;aaa\007bbb' prints bbb
printf '\033]2;aaa\007\\bbb' prints \bbb
printf '\033]2;a\ra\na\033bbb' prints bbb
printf '\033]2;a\ra\na\033\\bbb' prints bbb
printf '\033]2;a\ra\na\007bbb' prints bbb
       In each case the title is set to aaa
FIXED-IN: 19.12.0

M  +39   -25   src/Vt102Emulation.cpp
M  +1    -1    src/Vt102Emulation.h

https://invent.kde.org/kde/konsole/commit/324d78c07fc4fe2cdb2219a9e042a969df73d39c
Comment 10 Kurt Hindenburg 2019-11-02 16:10:36 UTC
Git commit 324d78c07fc4fe2cdb2219a9e042a969df73d39c by Kurt Hindenburg, on behalf of Mariusz Glebocki.
Committed on 02/11/2019 at 16:01.
Pushed by scmsync into branch 'master'.

Fix OSC sequence parsing

printf '\033]2;aaa\033bbb' prints bbb
printf '\033]2;aaa\033\\bbb' prints bbb
printf '\033]2;aaa\033' prints nothing;
        title is changed when next character is received.
printf '\033]2;aaa\033\\' prints nothing
printf '\033]2;aaa\007bbb' prints bbb
printf '\033]2;aaa\007\\bbb' prints \bbb
printf '\033]2;a\ra\na\033bbb' prints bbb
printf '\033]2;a\ra\na\033\\bbb' prints bbb
printf '\033]2;a\ra\na\007bbb' prints bbb
       In each case the title is set to aaa
FIXED-IN: 19.12.0

M  +39   -25   src/Vt102Emulation.cpp
M  +1    -1    src/Vt102Emulation.h

https://commits.kde.org/konsole/324d78c07fc4fe2cdb2219a9e042a969df73d39c
Comment 11 Kurt Hindenburg 2020-01-03 15:49:05 UTC
This fix appears to have broken tmux copy - https://bugs.kde.org/show_bug.cgi?id=415249