You are not logged in.

#1 2010-04-11 15:17:39

AndreasBWagner
Member
From: Boston, MA, USA
Registered: 2010-03-05
Posts: 17
Website

zsh change cursor color to indicate vi mode

Hello, I have written this for the .zshrc to change the cursor color to red when in cmd mode on the zsh command line.

zle-keymap-select () {
if [ $KEYMAP = vicmd ]; then
echo -ne "\033]12;Red\007"
else
echo -ne "\033]12;Grey\007"
fi
}
zle -N zle-keymap-select
zle-line-init () {
zle -K viins
echo -ne "\033]12;Grey\007"
}
zle -N zle-line-init
bindkey -v

It works well in urxvt however my tty does not know what to do with the escape codes so It just prints them to the command line. Is there any command for changing the cursor color that is for urxvt only? I think this would fix the problem.

Thanks,
Andreas

Offline

#2 2010-04-30 21:03:25

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: zsh change cursor color to indicate vi mode

I tried this but it's not working unfortunately but it might help you if you are better than me at zsh coding

zle-keymap-select () {
    if [ "$TERM" = "rxvt-256color" ]; then
        if [ $KEYMAP = vicmd ]; then
            echo -ne "\033]12;Red\007"
        else
            echo -ne "\033]12;Grey\007"
        fi
    fi
}
zle -N zle-keymap-select
zle-line-init () {
zle -K viins
}
zle -N zle-line-init

Offline

#3 2010-04-30 22:03:13

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: zsh change cursor color to indicate vi mode

This is simply awesome. Just need to figure out how to get it to use the green I've defined in Xdefaults...

I'd wager that more than just rxvt can parse the escape codes properly, so I would personally use:

if [ "$TERM" != "linux" ]; then ....

Offline

#4 2010-05-01 02:23:02

AndreasBWagner
Member
From: Boston, MA, USA
Registered: 2010-03-05
Posts: 17
Website

Re: zsh change cursor color to indicate vi mode

Cool! The extra $TERM conditional works. Thank you.

With xterm the color changing does not work as well, the cursor color only changes back to insert-mode-color once text is being typed.

This is working for me. I may simplify it later.

zle-keymap-select () {
    if [ $TERM = "rxvt-256color" ]; then
        if [ $KEYMAP = vicmd ]; then
            echo -ne "\033]12;Red\007"
        else
            echo -ne "\033]12;Grey\007"
        fi
    fi
}
zle -N zle-keymap-select
zle-line-init () {
    zle -K viins
    if [ $TERM = "rxvt-256color" ]; then
        echo -ne "\033]12;Grey\007"
    fi
}
zle -N zle-line-init
bindkey -v

There are many colorname choices in /usr/share/X11/rgb,txt

You can also add colors. Or just use rgb values directly, apparently. More about the color stuff here.

EDIT: You can just use the hex as you defined it in your .Xdefaults:

echo -ne "\033]12;#83C048\007"

Last edited by AndreasBWagner (2010-05-01 02:48:28)

Offline

#5 2010-05-01 02:53:12

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: zsh change cursor color to indicate vi mode

Oh very cool. Sure enough, using #xxxxxx works for specifying colors by hex value.

And unfortunately, you're also right about the limited terminal support. Looks like screen can't change the cursor color via escape codes even if you try to fool it into thinking its rxvt. Ah well.

Edit: looks like im too slow on the submit button.

Last edited by falconindy (2010-05-01 02:53:42)

Offline

#6 2010-05-04 02:36:34

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: zsh change cursor color to indicate vi mode

Strange, discovered that this addition causes me to segfault. The most easily repeatable is to do something like this:

$ echo "foo bar
> ^C

That is, start a quoted string, and Control-C out of after getting a newline at a PS2.

Here's the section of .zshrc that's causing the issue:

bindkey -v
zle-keymap-select () {
  if [ "$TERM" = "rxvt-256color" ]; then
    if [ $KEYMAP = vicmd ]; then
      echo -ne "\033]12;#ff6565\007"
    else
      echo -ne "\033]12;#93d44f\007"
    fi
  fi
}; zle -N zle-keymap-select
zle-line-init () {
  zle -K viins
  echo -ne "\033]12;#93d44f\007"
}; zle -N zle-line-init

Can anyone else here replicate this?

Offline

#7 2010-05-04 03:41:55

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: zsh change cursor color to indicate vi mode

@falcon works for me.
@OP nice thing, thanks smile

Offline

Board footer

Powered by FluxBB