[Top][All Lists]

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

[PATCH] Support configurable mode strings in prompt

From: Dylan Cali
Subject: [PATCH] Support configurable mode strings in prompt
Date: Thu, 28 Aug 2014 22:22:07 -0500

Hi all,

This is a patch to readline that enhances the current
show-mode-in-prompt feature.  It adds support for user-configurable
mode strings instead of hard-coded mode chars.  It also adds support
for the '\m' escape sequence, which allows users to indicate exactly
where in their prompt they would like the mode string expansion to
occur.  If not used, then the mode is simply prefixed as usual.

I am a heavy user of the vi stream editing mode in bash, and have been
using this patch to great effect at work and at home.  Having now used
it for several days, I think it's stable enough to introduce to the
mailing list.

The newly supported options are:

set vi-mode-str1 [str]        # insert mode string, default= (ins)
set vi-mode-str2 [str]        # movement mode string, default= (cmd)
set emacs-mode-str [str]  # emacs mode string, default= (emacs)

If a string is not provided then that mode string is unset (e.g. if
you wanted to have a mode string for vi movement mode, but nothing
when in insert mode).  I've been doing this for non-bash prompts like
gdb and python:

$ set vi-mode-str1   # unset
$ set vi-mode-str2 ! # bang for command mode

which in gdb looks like:
(gdb)   # insert mode
!(gdb)  # command mode

In bash you can now do something like:
PS1='address@hidden \m \w$ '

which will expand to:
address@hidden (ins) ~$
address@hidden (cmd) ~$

depending on which mode you're in.

I tried to impact the existing code base as little as possible to
implement this feature, and was largely successful in that effort.
The only parts that gave me some trouble were in update_line and
rl_redisplay.  Basically, the existing relative movement/invisible
char counting logic broke down for prompts that have invisible
characters and use dynamic mode strings.

After struggling mightily to get the existing logic to work, I finally
took the "easy" way out and simply do a full reprint of the prompt if
it has invisible characters, skipping the relative redisplay logic
entirely.  I noticed no performance impact, so hopefully this is okay.

In addition to the attached patch, my changes are also available on a
feature branch:

git clone address@hidden:calid/readline.git -b modestrs

you can view this patch in action at: http://youtu.be/ie-18687WH0

Chet - this patch incorporates my long-prompt vi search mode fix from
the other day (first patch in the file), so just a heads up


Attachment: readline-modestrs.patch
Description: Text Data

reply via email to

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