prompt strings with non-ansi escape sequences

35 views
Skip to first unread message

p...@bothner.com

unread,
Jun 18, 2016, 3:14:35 PM6/18/16
to jline-dev
I request a mechanism for JLine3 to emit uninterpreted escape sequences in prompt
strings, as well as delimiting highlighted tokens.  Specifically, I suggest extending
the syntax of the readLine prompt and the secondary-prompt-pattern with zsh-style
"%{xxx%}" delimiters: The text "xxx" is emitted, but not interpreted by jline.

Jline already supports AttributedStrings, and prompt strings can contain the common
ansi/xterm highlighting and colors.  However, I need to go beyond this.

For both prompt strings and highlighting it can be desirable to mark sections of the text with
more high-level "semantic" properties, such as "prompt" or "string-literal", rather than just
low-level "presentation" properties, such as "blue" or "bold".  The DomTerm terminal emulator
supports putting text inside spans with various attributes; various escape sequences are
available for this, including ones for variable kinds of prompts.  I don't propose that jline
know about these escape sequences; just that jline be able to emit them.

There would be an compatibility break with existing code, since we'd change the readLine prompt
to a template containing "%{...%}" (and %%) - these would no longer be literal text.  But
such prompts are rare (non-existent?), and before jline3 is released is a good time to
make this change.  (We could continue with the existing methods taking literal promps,
and add new ones that take templates, but that seems excessive.)

To implement this feature the AttributedString class needs to be more extensible.
The simplest mechanism I can think of is to define a new AttributedStyle.GENERIC_ESCAPE
object, along with a corresponding F_GENERIC_ESCAPE int style value.  Any characters with the
F_GENERIC_ESCAPE style are considered to take 0 columns, and are printed as-is
with no interpretation. Translating a prompt pattern containing %{xxx%} would just be a
matter of xxx with the F_GENERIC_ESCAPE style.

I assume there are some complications with this idea, but I'm willing to try implementing
it if you think it makes sense.

Guillaume Nodet

unread,
Jun 21, 2016, 5:40:48 PM6/21/16
to jlin...@googlegroups.com
The idea sounds good to me.

--
You received this message because you are subscribed to the Google Groups "jline-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages