all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* term-mode doesn't recognize "set window title" instruction
@ 2016-11-20 18:06 York Zhao
  2016-11-22 19:47 ` York Zhao
  2016-11-23  4:31 ` Bob Proulx
  0 siblings, 2 replies; 5+ messages in thread
From: York Zhao @ 2016-11-20 18:06 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hi list,

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!


Thanks in advance


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: term-mode doesn't recognize "set window title" instruction
  2016-11-20 18:06 term-mode doesn't recognize "set window title" instruction York Zhao
@ 2016-11-22 19:47 ` York Zhao
  2016-11-22 20:27   ` John Mastro
  2016-11-23  4:31 ` Bob Proulx
  1 sibling, 1 reply; 5+ messages in thread
From: York Zhao @ 2016-11-22 19:47 UTC (permalink / raw)
  To: help-gnu-emacs

Any idea?

On Nov 20, 2016 1:06 PM, "York Zhao" <gtdplatform@gmail.com> wrote:

> Hi list,
>
> 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!
>
>
> Thanks in advance
>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: term-mode doesn't recognize "set window title" instruction
  2016-11-22 19:47 ` York Zhao
@ 2016-11-22 20:27   ` John Mastro
  0 siblings, 0 replies; 5+ messages in thread
From: John Mastro @ 2016-11-22 20:27 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

York Zhao <gtdplatform@gmail.com> wrote:
> Any idea?
>
> On Nov 20, 2016 1:06 PM, "York Zhao" <gtdplatform@gmail.com> wrote:
>
>> Hi list,
>>
>> 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!

I don't know how to make that work with term-mode, but an alternative to
outright removing that line would be to do something like:

    if [ -z "$INSIDE_EMACS" ]; then
        # set window title, unless inside emacs
        PS1='\[\033]0;${PWD//[^[:ascii:]]/?}\007\]'
    else
        PS1=''
    fi
    PS1="$PS1"'\u@\h $ '             # user@host $<space>

Thought it was worth mentioning.

        John



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: term-mode doesn't recognize "set window title" instruction
  2016-11-20 18:06 term-mode doesn't recognize "set window title" instruction York Zhao
  2016-11-22 19:47 ` York Zhao
@ 2016-11-23  4:31 ` Bob Proulx
  2016-11-23  5:20   ` York Zhao
  1 sibling, 1 reply; 5+ messages in thread
From: Bob Proulx @ 2016-11-23  4:31 UTC (permalink / raw)
  To: York Zhao; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: term-mode doesn't recognize "set window title" instruction
  2016-11-23  4:31 ` Bob Proulx
@ 2016-11-23  5:20   ` York Zhao
  0 siblings, 0 replies; 5+ messages in thread
From: York Zhao @ 2016-11-23  5:20 UTC (permalink / raw)
  To: help-gnu-emacs

This is exactly what I was looking for. Your post is super informative,
thank you so much.

I'm in bed now, will try it tomorrow.

Thanks again!

On Nov 22, 2016 11:31 PM, "Bob Proulx" <bob@proulx.com> wrote:

> 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
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-11-23  5:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-20 18:06 term-mode doesn't recognize "set window title" instruction York Zhao
2016-11-22 19:47 ` York Zhao
2016-11-22 20:27   ` John Mastro
2016-11-23  4:31 ` Bob Proulx
2016-11-23  5:20   ` York Zhao

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.