bug-ncurses
[Top][All Lists]
Advanced

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

Re: terminfo status line for screen-s


From: Craig R. Skinner
Subject: Re: terminfo status line for screen-s
Date: Mon, 3 Nov 2014 16:51:44 +0000
User-agent: Mutt/1.5.22 (2013-10-16)

On 2014-11-01 Sat 13:14 PM |, Thomas Dickey wrote:
> On Wed, Oct 29, 2014 at 08:36:25PM +0000, Craig R. Skinner wrote:
> > Add ':hs' (has extra status line) to screen-s
> > Like vt100-s, xterm+sl, xterm+sl-twm, sun-s & sun-e-s
> > 

Thanks for investigating this Thomas.

While I'm new to terminfo/termcap things, I'll try to help.

> 
> hmm - I had not noticed that (previous discussion had focussed on tsl and 
> fsl).
>  
> However, it is unclear if _all_ status lines should be noted with "hs".
> The relevant text in terminfo(5):
> 
> tack has a test for the feature (usually tack is correct).

This is how I noticed it; I've recently begun using tmux on OpenBSD i386
and discovered tmux sets its internal TERM to 'screen' by default.

The TERM I ssh on to my servers with is 'xterm+sl', so thought I'd have
a go changing my TERM to screen-s instead.


<address@hidden:~>$ print $SHELL
/bin/sh
<address@hidden:~>$ print $TERM
xterm+sl
<address@hidden:~>$ export TERM=screen-s
<address@hidden:~>$ ssh teak
...
<address@hidden:~>$ ls .profile
colorls: .profile: No such file or directory
<address@hidden:~> (1) $ cat /etc/profile
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
#

# Solve amd symlink related window decoration issues:
# Also needed for tmux as $TERM = 'screen'
[[ ${PWD} == ${HOME} ]] ||
{
        # /nonexistent?
        [[ -d ${HOME} ]] && cd
}


[[ -o interactive ]] &&
{
        [[ -n ${XTERM_VERSION} ]] && I='I'
        eval $(tset -${I}sQ '-munknown:?vt220' ${TERM})


        HISTSIZE='100'
        HISTFILE="${HOME}/.sh_history"
        export HISTSIZE HISTFILE


        # If the terminal can put colours;
        [[ $(tput colors) -gt 7 ]] &&
        {
                # terminfo(5) colours
                # black         0
                # red           1
                # green         2
                # yellow        3
                # blue          4
                # magenta       5
                # cyan          6
                # white         7

                # Set a random colour between red & cyan
                tp_colour=$(tput setaf $(jot -r 1 1 6))
                tp_colour_red=$(tput setaf 1)
        }


        # Settings:
        set -o trackall
        set -o csh-history
        set -o bgnice


        # Aliases:
        alias rm='rm -i'
        alias cp='cp -i'
        alias mv='mv -i'
        alias df='df -h'
        alias du='du -h'
        alias ls='ls -F'

        alias quit='print use: exit'
        alias logout='quit'
        alias logoff='quit'
        alias bye='quit'
        alias cls='print use: clear'
        alias p='ps -l'
        alias j='jobs'

        alias mkpasswd='apg -M SNCL -E 01OIl\| -n 1'
        alias ns='netstat -naf inet'
        alias traceroute='traceroute -I'
        alias mutt='mutt -y'
        alias sube='sudo -H -i -u'

        alias m2u="tr ''\015'' ''\012''"
        alias u2m="tr ''\012'' ''\015''"
        alias dos2unix="tr '\\r' '\\n'"
        alias unix2dos="tr '\\n' '\\r'"


        export PAGER='less'
        export MANPAGER=${PAGER}
        export LESS="--LONG-PROMPT --ignore-case"


        [[ -n ${tp_colour} ]] &&
        {
                whence -p colorls > /dev/null && alias ls='colorls -GF'

                # Many tput calls slow down logins, export once only when 
needed:
                alias man='man_with_colours'

                function man_with_colours
                {
                        # 
http://unix.stackexchange.com/questions/119/colors-in-man-pages
                        # 
http://unix.stackexchange.com/questions/108699/documentation-on-less-termcap-variables
                        # 
https://wiki.archlinux.org/index.php/Man_Page#Using_less_.28Recommended.29

                        [[ -n ${LESS_TERMCAP_md} ]] ||
                        {
                                print 'exporting colours...'

                                # terminfo(5)
                                # blink mb      turn on blinking
                                # bold  md      turn on bold (extra bright) mode
                                # sgr0  me      turn off all attributes
                                # dim   mh      turn on half-bright mode
                                # rev   mr      turn on reverse video mode
                                # sms   so      begin standout mode
                                # rmso  se      exit standout mode
                                # smul  us      begin underline mode
                                # rmul  ue      exit underline mode

                                # terminfo(5) colours
                                # black         0
                                # red           1
                                # green         2
                                # yellow        3
                                # blue          4
                                # magenta       5
                                # cyan          6
                                # white         7

                                export LESS_TERMCAP_mb=$(tput mb; tput AF 1) # 
blink red
                                export LESS_TERMCAP_md=$(tput md; tput AF 6) # 
bold cyan
                                # default: export LESS_TERMCAP_me=$(tput me) # 
normal
                                # tput: Unknown terminfo capability `mh':
                                export LESS_TERMCAP_mh=$(tput AF 5) # magenta; 
see if this ever shows up....
                                # default: export LESS_TERMCAP_mr=$(tput mr)
                                export LESS_TERMCAP_so=$(tput so; tput AF 3) # 
stand out yellow
                                export LESS_TERMCAP_se=$(tput me)
                                export LESS_TERMCAP_us=$(tput us; tput AF 2) # 
underlined green
                                export LESS_TERMCAP_ue=$(tput me)
                        }
                        \man "$@"
                }
        }


        whence -p vim > /dev/null &&
        {
                alias view='vim -R'
                export VIM_TMP="/var/tmp/${LOGNAME}//"
                [[ -d ${VIM_TMP} ]] ||
                {
                        mkdir ${VIM_TMP} && chmod 0700 ${VIM_TMP}
                }
                export EDITOR='vim'
        }


        HOSTNAME=${HOSTNAME:-$(hostname)}
        TAG="address@hidden"

        # terminfo(5)
        tp_bold=$(tput bold)
        tp_blink=$(tput blink)
        tp_underline=$(tput smul)
        tp_standout=$(tput smso)
        tp_normal=$(tput sgr0)


        # Adapted from <address@hidden>'s post:
        # http://marc.info/?l=openbsd-misc&m=141447819727360&w=2
        function _ps1_err
        {
                local _rc=$?
                [[ ${_rc} -eq 0 ]] || print -n 
"${tp_colour_red}${tp_blink}${tp_standout} (${_rc}) "
                return ${_rc}
        }

        # Mostly emulate ksh's PS1 \W
        function _ksh_W
        {
                case ${PWD} in
                        ${HOME})
                                print '~'
                                ;;
                        '/')
                                print '/'
                                ;;
                        *)
                                print "${PWD##*/}/"
                                ;;
                esac
        }


        # Mostly emulate ksh's address@hidden:\W
        PROMPT="<address@hidden:"'$(_ksh_W)>'

        if [[ ${LOGNAME} == 'root' ]]
        then
                PROMPT="${tp_standout}${PROMPT}"
        else
                if [[ -n ${tp_colour} ]]
                then
                        PROMPT="${tp_colour}${PROMPT}"
                        # Randomly enable bold;
                        [[ $(($RANDOM%2)) -eq 0 ]] && 
PROMPT="${tp_bold}${PROMPT}"

                # Else if no colours, always be bold;
                else
                        PROMPT="${tp_bold}${PROMPT}"
                fi
        fi

        PROMPT="${PROMPT}${tp_normal}"'$(_ps1_err)'

        # Finally, append the '#|$' and [space] characters
        if [[ ${LOGNAME} == 'root' ]]
        then
                PROMPT="${PROMPT}#"
        else
                PROMPT="${PROMPT}\$"
        fi

        # All done setting PS1
        PS1="${PROMPT}${tp_normal} "


        # terminfo(5): hs: has extra status line
        # FIXME screen-s is missing :hs in /etc/termcap
        tput hs &&
        {
                WLS=$(tput ts) # move to status line, column #1
                WLE=$(tput fs) # return from status line
        }


        # If window decorations:
        [[ -n ${WLS} ]] &&
        {
                function _stripe
                {
                        local _return_code=$?
                        print -n "${WLS}"$(_ksh_W)" <${TAG}>${WLE}" > /dev/tty
                        return ${_return_code}
                }

                alias cd='_cd'
                function _cd
                {
                        \cd "$@" && _stripe
                }

                alias ftp='_ftp'
                function _ftp
                {
                        \ftp "$@"
                        _stripe
                }

                alias ssh='_ssh'
                function _ssh
                {
                        \ssh "$@"
                        _stripe
                }

                alias telnet='_telnet'
                function _telnet
                {
                        \telnet "$@"
                        _stripe
                }

                alias rlogin='_rlogin'
                function _rlogin
                {
                        \rlogin "$@"
                        _stripe
                }

                alias su='_su'
                function _su
                {
                        \su "$@"
                        _stripe
                }

                alias sudo='_sudo'
                function _sudo
                {
                        \sudo "$@"
                        _stripe
                }

                alias tip='_tip'
                function _tip
                {
                        \tip "$@"
                        _stripe
                }

                alias cu='_cu'
                function _cu
                {
                        \cu "$@"
                        _stripe
                }

                _stripe
        }
}

<address@hidden:~>$ man login
exporting colours...
LOGIN(1)                   OpenBSD Reference Manual             LOGIN(1)

NAME
     login - log into the computer
....
...
..



Colours, bold & underline work fine (man, mutt, vim, tmux),
but no xterm status line, not updated after cd, sudo, ftp, ssh, etc.

When commenting out the :hs test in /etc/profile, _stripe() operates,
but the status line is printed at the prompt, before $PS1.

This could be due to:
<address@hidden:~>$ getcap -c ts -f /etc/termcap screen-s
=\E_
<address@hidden:~>$ getcap -c fs -f /etc/termcap screen-s
=\E\\

Compared with:
<address@hidden:~>$ getcap -c ts -f /etc/termcap xterm+sl
=\E]0;
<address@hidden:~>$ getcap -c fs -f /etc/termcap xterm+sl
=^G



A screen FAQ about setting xterm's title bar says to override terminfo's
:ts :fs *and* :hs with entries more like those from xterm+sl;-

termcapinfo xterm*|rxvt*|kterm*|Eterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
http://aperiodic.net/screen/faq#how_can_screen_use_xterm_s_title_bar

<address@hidden:~>$ getcap -c hs -f /etc/termcap screen-s
<address@hidden:~>$ getcap -c hs -f /etc/termcap xterm+sl

<address@hidden:~>$




tmux(1) uses alternative :ts & :fs to screen-s terminfo:

 set-titles [on | off]
     Attempt to set the client terminal title using the tsl and fsl
     terminfo(5) entries if they exist. tmux automatically sets these to
     the \e]2;...\007 sequence if the terminal appears to be an xterm.
     This option is off by default. Note that elinks will only attempt
     to set the window title if the STY environment variable is set.

 default-terminal terminal
     Set the default terminal for new windows created in this session -
     the default value of the TERM environment variable. For tmux to
     work correctly, this must be set to .screen. or a derivative of it.

 The TERM environment variable must be set to .screen. for all programs
 running inside tmux. New windows will automatically have .TERM=screen.
 added to their environment, but care must be taken not to reset this in
 shell start-up files.

There's lots of terminfo(5) items on the man page:
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux


Looking at the source code for tmux
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/tmux/tty.c
Revision 1.105
Use the tsl and fsl terminfo(5) capabilities to update terminal title
and automatically fill them in on terminals with the XT capability
(which means their title setting is xterm-compatible). From hsim at
gmx.li.

The function tty_set_title() doesn't check screen's terminfo :hs, maybe
because it isn't present?



> 
> > A guess that :es is valid (also for the above as \E sequences appear?):
> 
> :es doesn't refer to the sequences used for going to/from the status line,
> but to the usability of escape sequences while the cursor is on the status
> line.

OK.

> 
> So... what configuration details can you provide to help me test (and 
> document)
> this change?
> 

The above probably isn't the best, but that's how I noticed :hs
& saw :es frequently with it.


Cheers,
-- 
Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7



reply via email to

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