help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: term-mode doesn't recognize "set window title" instruction


From: Bob Proulx
Subject: Re: term-mode doesn't recognize "set window title" instruction
Date: Tue, 22 Nov 2016 21:31:57 -0700
User-agent: NeoMutt/20161104 (1.7.1)

York Zhao wrote:
> In my .bashrc file, I have the following to set the terminal window title
> and customize the shell prompt:
> 
>   PS1='\[\033]0;${PWD//[^[:ascii:]]/?}\007\]' # set window title
>   PS1="$PS1"'\u@\h $ '             # user@host $<space>
> 
> The first line makes the current directory shown as the title of the
> terminal window, and the prompt would be shows as:
> 
>   york@linux-host $
> 
> However, the first line which sets the terminal window title confused the
> term-mode, and the following is what gets shown in term-mode buffer:
> 
>   0;/home/yorkyork@linux-host $
> 
> Of course the problem can be addressed by removing the first line in my
> .bashrc file which sets the title of terminal window. However, I would love
> to know if there's a way to allow the terminal window title to be shown,
> while at the same time, also making Emacs term-mode happy!

At one level the problem you are running into is that you are using a
terminal specific escape sequence that is specific to one type of
terminal and are not checking first to see if that is valid for that
terminal type and you are running a different type of terminal where
it is not valid.

You may be unaware that the terminal environment is declared by using
the TERM variable to hold the name of the terminal type.  The
capabilities of the terminal are described in the terminfo / termcap
terminal capabilities database.  Programs use that database to look up
escape sequences that they want to use.  (One example is "tput" which
is a standalone program that can query the database and emit the
proper escape sequences appropriate for the current $TERM value.)

A command line user will see many different TERM types.  Screen and
tmux users will see TERM=screen within a screen session.  Emacs users
will see either TERM=dumb or TERM=eterm-color.  I use xterms and
therefore I see TERM=xterm in my terminal windows.  Others will see
gnome or konsole or whatever.  The world is not yet 100% homogeneous
yet and the differences can not yet be ignored.

Bash ships with a default .bashrc file and the Debian packaging of it
has this:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='printf "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
esac

That is one example.  There are others.  If your .bashrc file
protected your title setting escape sequences to terminals that
supported it then you wouldn't have any problems inside your emacs
shell-mode.

Checking emacs shell-mode you will find that TERM=dumb and in
terminal-mode it is TERM=eterm-color.  Neither of those terminals
support setting the title.

At another level another problem is that you are using PS1 when you
should really be using PROMPT_COMMAND.  Using PS1 requires protecting
the non-printable characters of the prompt with \[...\] as you are
doing in your example.  However if you were using PROMPT_COMMAND then
no such protection is needed.  It is simpler.  You should be using
PROMPT_COMMAND for this instead of PS1.

> However, I would love to know if there's a way to allow the terminal
> window title to be shown, while at the same time, also making Emacs
> term-mode happy!

You do go and ask if there is some way to make use of this
information.  The answer as far as I know is no there isn't.  Neither
of the current shell-mode and terminal-mode terminal emulations
support doing this.  No one has programmed them for it.  Sorry.

This doesn't mean that couldn't ever support it.  If someone were to
spend the effort to add that functionality then they should support
it.  But as far as I know this features is not yet supported.

Note that if you were to add that feature please be aware that many
people will not want titles consume precious space.  Please make it
possible to avoid titles for people who are happy with the current
behavior without titles.  Because a lot of that is extra redundant
information with information that PS1 can provide in the prompt and
Emacs can provide in the mode line.  Personally I would hate to give
up even one more line of vertical space for this since it already
exists in my prompt or in my mode line.

Good luck and Happy Hacking!

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]