You are not logged in.

#1 2010-10-11 16:21:24

mirci
Member
Registered: 2010-09-25
Posts: 7

gnu readline with vi mode change visualization

After a lot of searching how to get some kind of vi mode indicator working with GNU readline I've decided to hack readline myself. It's working fine for me and because I'm happy archlinux user I've decided to share my findings here, so maybe somebody will find it useful too.

  1. there is a patch to readline needed - I've created AUR package readline-vi-mode-changed-hook

  2. additional logic / configuration to provide your visualization

To not double post what I've already wrote in more detailed way, here is the link to my personal blog where I've documented the whole thing.

There are however few things still bugging me and maybe somebody will be able to help me with that. The particular thing which I would like to solve is to get escape sequence for changing cursor color working inside screen and tmux. I've found trick for screen but what is expectable is that when switching windows the cursor color is not reset by screen to last color set in particular window. Because cursor color sequence is not really a standard nor part of termcap / terminfo I feel it will not be so easy / possible ?

Last edited by mirci (2010-10-11 19:26:06)

Offline

#2 2010-10-11 21:50:47

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: gnu readline with vi mode change visualization

Does the readline maintainer have any interesting in your patch?

Offline

#3 2010-10-12 19:27:24

mirci
Member
Registered: 2010-09-25
Posts: 7

Re: gnu readline with vi mode change visualization

steve___ wrote:

Does the readline maintainer have any interesting in your patch?

In my blog post I wrote ...

"Note that the patch works for me, I've intentionally touched only absolutely necessary readline code to leave the patch very simple however I am aware that it can be optimized better or done in more integrated way. It was intended for my personal use and I don't think it is ready for including in mainstream readline."

So I haven't communicated to maintainer of the arch 'readline' package, neither to the maintainer of the readline source code. I wouldn't mind to including this to mainstream ... however at least the configuration (which is done now by process environment) should be done inside of readline configuration file .inputrc ... after that one can take a benefit of conditional configuration (terminal or application specific). If there would be some interest for this functionality from community I can work on it. I've just posted what I have so far, what works in some way, and awaiting some comments maybe suggestions how to improve it. For example I'm not sure if the idea of spawning the new process on each mode change is the best (that's why I placed there an option to write to named pipe). I think important is to have solution which works without any modification needed to existing applications which use readline.

Offline

#4 2010-11-05 22:58:30

mirci
Member
Registered: 2010-09-25
Posts: 7

Re: gnu readline with vi mode change visualization

I've improved / reworked my readline patch so that the configuration is done in the '.inputrc' file and can look like this ...

# prompt format for command mode
set vi-command-prompt \001\033[1;37m\002{}\001\033[0m\002

$if python
    set vi-command-prompt \001\033[1;37;41m\002>\001\033[0m\002{}
$endif

# vi mode changed script
set vi-mode-changed-bin /home/mirci/.inputrc_vi_mode_changed

It works fine even with multiline prompts (changing just last line always). One can refer to the last line of application prompt by '{}' pattern in the prompt format.
Prompt visualization comes very handy eg. inside screen or tmux, as changing of the cursor color doesn't really work there.

I will try to contact readline maintainer if it will be possible to push this patch to readline mainline. If somebody will want to try it out there is a package on AUR here.

You can find details at http://kvakaren.blogspot.com/2010/11/gn … ion-2.html.

Offline

#5 2010-11-13 21:40:25

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: gnu readline with vi mode change visualization

Am using this with GNU screen, and it works great (no change in cursor color, of course, but I think I actually prefer that, as it isn't inconvenient to look at the window title in DWM). Thanks for sharing the patch--I don't know how I ever lived without it smile


Registed Linux User 483618

Offline

#6 2010-11-13 23:29:14

lavandero
Member
Registered: 2010-11-13
Posts: 6

Re: gnu readline with vi mode change visualization

Would you be interested in porting this to NetBSD editline (libedit)?

Open/FreeBSD also use it, just in case that qualifies as incentive.

Offline

#7 2010-11-15 10:46:26

mirci
Member
Registered: 2010-09-25
Posts: 7

Re: gnu readline with vi mode change visualization

Sara wrote:

Am using this with GNU screen, and it works great (no change in cursor color, of course, but I think I actually prefer that, as it isn't inconvenient to look at the window title in DWM). Thanks for sharing the patch--I don't know how I ever lived without it smile

Well I started with the window title as I use Xmonad, then I realized that looking up or down on screen isn't very convenient for me (mainly because of a big screen I have) but it's still fine, so I was thinking about visualization which would be closest to the prompt location, cursor color was natural choice however it is not very reliable in terminal multiplexers and in general. The latest and my favorite now is the change of prompt itself (eg. bold version).

Anyway thanks for feedback, firstly when published this I thought nobody is using VI mode with readline judging based on almost no feedback at all. It's cool that at least somebody found this patch useful wink.


lavandero wrote:

Would you be interested in porting this to NetBSD editline (libedit)?

Open/FreeBSD also use it, just in case that qualifies as incentive.

I don't use any application which uses editline. I know it just in the meaning that it is implementing similar functionality as readline do. I guess then some applications usually can be compiled with readline or editline (if author thinks it can be useful based on different licenses and so on) ... does the *BSD systems do it that way ? Anyway I have editline in my mind if I would maybe implement some application where I would need readline functionality. Readline is fine but to be honest I found the source code of it not very nice. So to your question ... as I'm not user of the editline so far I am not planing to port this patch there anytime soon.

Just out of my curiosity which let's say well known applications can be compiled against readline and editline, is it out of box provided by upstream or usually patches are done for it. How it works in *BSD then ? In my archlinux box I frequently use mainly 2 readline applications (bash, i/python).

Offline

#8 2010-11-16 00:56:19

lavandero
Member
Registered: 2010-11-13
Posts: 6

Re: gnu readline with vi mode change visualization

well, thanks to some apple patches, editline is becoming almost a drop in replacement. and by that i mean empty functions that do nothing, kinda like when you switch back between linking against gnutls and openssl and notice some functions always return true.

but the nice thing about editline is that it's much smaller and easier to hack than readline, and it will likely stay this way. and it has, imo most if not all of the important readline bits.

Last edited by lavandero (2010-11-16 00:57:17)

Offline

#9 2010-11-26 03:49:16

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: gnu readline with vi mode change visualization

I've modified my screenrc in such a way that now, the patch is even more convenient. What I did is made my hardstatus message show at the bottom of gnu screen, so I no longer have to look up to see what mode I'm in (or in what user directory I'm in). This means that the hardstatus message at the top remains unchanged, but this perfectly fine with me (it remains urxvt).

Here are the relevant lines from my screenrc (I don't think you need to see my caption code, but just in case):

caption string "%{= dk}%-Lw%{= dB}%{+b}[%n %t]%{-b}%{= dk}%+Lw%1`"
hardstatus alwayslastline
caption always

Here's a screenshot of it in action:
201011252245581280x800s.th.png

See the bottom. I'm currently in "insert" mode, and in my home directory (hence, the ~).

Thanks again for the great patch.

Last edited by Sara (2010-11-26 03:55:06)


Registed Linux User 483618

Offline

Board footer

Powered by FluxBB