commandline: strip_escape: strip xterm OSC commands in $PS1

Correctly deal with prompts like (appear in debian/ubuntu):
  PS1='\[\e]0;\u@\h: \w\a\]\u@\h:\w\$'
  PS1='\[\e]0;\u@\h: \w\e\\\]\u@\h:\w\$'

Based on patch provided provided by Sergey Nizovtsev
    https://bugs.launchpad.net/ubuntu/+source/mc/+bug/330633

Signed-off-by: Sergei Trofimovich <st@anti-virus.by>
This commit is contained in:
Mikhail S. Pobolovets 2009-05-05 16:46:10 +03:00 committed by Sergei Trofimovich
parent f7781c16e0
commit 9041e6c81f
1 changed files with 28 additions and 0 deletions

View File

@ -904,6 +904,34 @@ strip_ctrl_codes (char *s)
if (*(++r) == '[') {
/* strchr() matches trailing binary 0 */
while (*(++r) && strchr ("0123456789;?", *r));
} else
if (*r == ']') {
/*
* Skip xterm's OSC (Operating System Command)
* http://www.xfree86.org/current/ctlseqs.html
* OSC P s ; P t ST
* OSC P s ; P t BEL
*/
char * new_r = r;
for (; *new_r; ++new_r)
{
switch (*new_r)
{
/* BEL */
case '\a':
r = new_r;
goto osc_out;
case ESC_CHAR:
/* ST */
if (*(new_r + 1) == '\\')
{
r = new_r + 1;
goto osc_out;
}
}
}
osc_out:;
}
/*