On 2006-01-26, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
> Zdenek Sekera wrote:
> 
> > > >> Example for an xterm, this changes the color of the cursor: >
> > > >>     if &term =~ "xterm"
> > > >>        let &t_SI = "\<Esc>]12;purple\x7"
> > > >>        let &t_EI = "\<Esc>]12;blue\x7"
> > > >>     endif
> > > >> NOTE: When Vim exits the shape for Normal mode will 
> > > remain.  The shape
> > > >> from before Vim started will not be restored.
> > > >> {not available when compiled without the +cursorshape feature}
> > > > 
> > > > And is there a way to have it restored?
> > ...
> > > I don't know. My guess (but it's only a guess) is: if you know what
> > > codes to send to set that default, try using these codes in an ":echo"
> > > statement at the VimLeave autocomand event.
> > 
> > I don't know the codes, unfortunately, but the idea of using VimLeave
> > is interesting. And why it's not done automatically in vim is perhaps
> > because there is no way to guarantee it can be done generically for
> > any terminal emulator. Bram?
> 
> The reason it can't be restored is that Vim doesn't know what the
> original color was.
> 
> > Does anyone know what codes need to be sent to at
> > least xterm to have the cursor shape/color restored on vim exit?
> 
> As far as I know it's impossible, there doesn't appear a way to obtain
> the cursor color that is in use when Vim is started.

(I'm catching up on some old unread list e-mail.)

According to the ctlseqs.ms document that came with xterm-165:


    Operating System Controls
    OSC Ps ; Pt ST
    OSC Ps ; Pt BEL
           Set Text Parameters.  For colors and font, if Pt is a
           "?", the control sequence elicits a response which con-
           sists of the control sequence which would set the
           corresponding value. ....
           ...
             Ps = 1 2  -> Change colors starting with text cursor to
           Pt


I executed this command at a Linux shell prompt,

    echo -e '\033]12;?\007' ; read x

and got the following response:

    ^[]12;rgb:ffff/ffff/ffff^G

After setting the cursor to red and repeating the command, I got
this:

    ^[]12;rgb:ffff/0000/0000^G

So, xterm does have the mechanism to obtain the cursor color when
vim is started.  I just don't know how to obtain the terminal's
response from within vim and don't have the time to experiment
further at the moment.  I did discover, though, that you can echo
back the color in that same format, so no parsing of the terminal
response would be necessary.

HTH,
Gary

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Wireless Division
                             | Spokane, Washington, USA

Reply via email to