zsh-workers
 help / color / Atom feed
* Feature request: italic style in region_highlight
@ 2019-12-30  1:29 Sebastian Gniazdowski
  2019-12-30 10:16 ` Roman Perepelitsa
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Gniazdowski @ 2019-12-30  1:29 UTC (permalink / raw)
  To: Zsh hackers list

Hi,
it would be nice if the italic escape (\e[3m) would have been
supported in the region_highlight array. Currently supported are only
bold, standout and underline. The escape is widely supported, e.g.: it
works on urxvt out of the box.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2019-12-30  1:29 Feature request: italic style in region_highlight Sebastian Gniazdowski
@ 2019-12-30 10:16 ` Roman Perepelitsa
  2019-12-30 16:07   ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Roman Perepelitsa @ 2019-12-30 10:16 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh hackers list

On Mon, Dec 30, 2019 at 2:30 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hi,
> it would be nice if the italic escape (\e[3m) would have been
> supported in the region_highlight array. Currently supported are only
> bold, standout and underline. The escape is widely supported, e.g.: it
> works on urxvt out of the box.

Zsh sort of supports italicized text through "standout" attribute in
ncurses. ncurses translates standout to italicized on some terminals
and to negative image on others.

    % zle_highlight=(default:standout)
    % export TERM=screen-256color
    % print -P '%Shello%s'
    hello
    % export TERM=xterm-256color
    % print -P '%Shello%s'
    hello

With TERM=screen-256color standout is italicized while with
TERM=xterm-256color it's negative image.

The terms "italicized" and "negative image" come from ECMA-48. Note
that it doesn't define "standout".

When printing text, you can use `colors` from contrib to bypass
ncurses. Confusingly enough, in `color` associative array the key for
italicized text is "standout" (negative image goes by "reverse").

    % autoload -Uz colors
    % colors
    % echo "\e[$color[standout]mhello$reset_color"

The only difference between $color[standout] and plain `3` is
readability. I know which version I prefer.

As far as I can tell, there is no way to specify italicized attribute
through zle_highlight or region_highlight. zle_highlight allows you to
override the default escape sequences used by fg and bg attributes. It
seems natural to extend this API to also allow overriding escape
sequences used by standout style. Then you would be able to do this:

    zle_highlight=(default:standout standout_begin_code:'\e[3m'
standout_stop_code:'\e[23m')

fg_start_code and fg_end_code specify the prefix and the suffix of a
single escape sequence. To avoid confusion, I've used begin/stop with
standout. It's awkward, as the natural pairing would be start/stop and
begin/end. Oh well.

Roman.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2019-12-30 10:16 ` Roman Perepelitsa
@ 2019-12-30 16:07   ` Bart Schaefer
  2019-12-30 16:26     ` Roman Perepelitsa
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2019-12-30 16:07 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, Zsh hackers list

On Mon, Dec 30, 2019 at 2:17 AM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> Zsh sort of supports italicized text through "standout" attribute in
> ncurses. ncurses translates standout to italicized on some terminals
> and to negative image on others.

The way the "colors" function/array have dealt with similar issues is
to declare e.g color[grey]=${color[black]} ... however, the difference
between negative image and italic may be too drastic to alias that to
standout.

> When printing text, you can use `colors` from contrib to bypass
> ncurses. Confusingly enough, in `color` associative array the key for
> italicized text is "standout" (negative image goes by "reverse").

I believe the use of "standout" there comes from the xterm
documentation (circa the time the colors function was contributed, it
may have since been updated).

>     zle_highlight=(default:standout standout_begin_code:'\e[3m'
> standout_stop_code:'\e[23m')
>
> fg_start_code and fg_end_code specify the prefix and the suffix of a
> single escape sequence. To avoid confusion, I've used begin/stop with
> standout. It's awkward, as the natural pairing would be start/stop and
> begin/end. Oh well.

Could use standout_enter/exit (or enter/end).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2019-12-30 16:07   ` Bart Schaefer
@ 2019-12-30 16:26     ` Roman Perepelitsa
  2020-01-01  0:07       ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Roman Perepelitsa @ 2019-12-30 16:26 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Sebastian Gniazdowski, Zsh hackers list

On Mon, Dec 30, 2019 at 5:08 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mon, Dec 30, 2019 at 2:17 AM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> > fg_start_code and fg_end_code specify the prefix and the suffix of a
> > single escape sequence. To avoid confusion, I've used begin/stop with
> > standout. It's awkward, as the natural pairing would be start/stop and
> > begin/end. Oh well.
>
> Could use standout_enter/exit (or enter/end).

enter/exit sounds better than my suggestion. Another option: on/off. I
haven't thought of it earlier but now I think it pretty good.

Shall I send a patch? I'd love to have this feature.

A related question. Would you (zsh elders) be receptive to my adding
percent escapes for italicized (%A and %a) and inverse video (%R and
%r) mode? %S and %s would stay unchanged.

Roman.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2019-12-30 16:26     ` Roman Perepelitsa
@ 2020-01-01  0:07       ` Bart Schaefer
  2020-01-02 19:18         ` Oliver Kiddle
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2020-01-01  0:07 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, Zsh hackers list

On Mon, Dec 30, 2019 at 8:27 AM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> enter/exit sounds better than my suggestion. Another option: on/off. I
> haven't thought of it earlier but now I think it pretty good.

Yes, on/off would be fine.

> Shall I send a patch? I'd love to have this feature.

I don't see why not.

> A related question. Would you (zsh elders) be receptive to my adding
> percent escapes for italicized (%A and %a) and inverse video (%R and
> %r) mode? %S and %s would stay unchanged.

I think %R and %r have been preempted for the spell correction prompt
(see SPROMPT in the manual, could probably stand to have a mention
added in the section with the rest of the prompt expansions).

Perhaps the way around this is to use %A/%a for "attribute" the way
%F/%f are use for foreground color.  Thus %A{03} would be italic
(where supported), %A{07} would be reverse, etc.  Your call whether to
define some counterpart of the ansi_colours array in prompt.c that
supplies symbolic names; Functions/Misc/colors has the ECMA-48 table.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2020-01-01  0:07       ` Bart Schaefer
@ 2020-01-02 19:18         ` Oliver Kiddle
  2020-01-02 19:45           ` Roman Perepelitsa
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2020-01-02 19:18 UTC (permalink / raw)
  To: Roman Perepelitsa, Zsh hackers list

Bart wrote:
> On Mon, Dec 30, 2019 at 8:27 AM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > enter/exit sounds better than my suggestion. Another option: on/off. I
> > haven't thought of it earlier but now I think it pretty good.
>
> Yes, on/off would be fine.
>
> > Shall I send a patch? I'd love to have this feature.
>
> I don't see why not.

That sounds useful, expecially italic.

The lack of free bits in zattr (TXT macros) may be something of an
impediment. It isn't really important to prompts but would matter for
zle. There may be ways to recover bits, for example we have both
TXTBOLDFACE and TXTNOBOLDFACE which allows the code to distinguish the
actions but is redundant in terms of tracking attributes.

> > A related question. Would you (zsh elders) be receptive to my adding
> > percent escapes for italicized (%A and %a) and inverse video (%R and
> > %r) mode? %S and %s would stay unchanged.

%O/%o (for "oblique") would be available. I realise that an oblique font
is not strictly the same as italic.

> Perhaps the way around this is to use %A/%a for "attribute" the way
> %F/%f are use for foreground color.  Thus %A{03} would be italic
> (where supported), %A{07} would be reverse, etc.  Your call whether to
> define some counterpart of the ansi_colours array in prompt.c that
> supplies symbolic names; Functions/Misc/colors has the ECMA-48 table.

I like the idea of %A{...} but would favour symbolic names over numbers
even if we can't guarantee that they are always correct. If people
want full control they can dump literal escapes. The % sequences are
generally friendlier.

Oliver

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2020-01-02 19:18         ` Oliver Kiddle
@ 2020-01-02 19:45           ` Roman Perepelitsa
  2020-01-03  2:30             ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Roman Perepelitsa @ 2020-01-02 19:45 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh hackers list

On Thu, Jan 2, 2020 at 8:18 PM Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
>
> That sounds useful, expecially italic.

Yesterday I started adding italic support throughout. Once it's there,
there would be no need for custom standout_on_code/standout_off_code
overrides. Plain "italic" style would surely be nicer.

> The lack of free bits in zattr (TXT macros) may be something of an
> impediment. It isn't really important to prompts but would matter for
> zle. There may be ways to recover bits, for example we have both
> TXTBOLDFACE and TXTNOBOLDFACE which allows the code to distinguish the
> actions but is redundant in terms of tracking attributes.

Yep, I've already discovered this. If this was C++, I would just make
zattr std::bitset<84> and be done with it. Once could wish. Instead,
I've made zattr a struct with 3 fields: attr for on/off attributes and
fg and bg for colors. Each of these 3 fields is 4 bytes (I could make
attr 2 bytes but it won't save anything due to alignment
requirements). I don't want to spent much of your time on this as it's
not close to being done. Will send a patch when I get through with it.

> %O/%o (for "oblique") would be available. I realise that an oblique font
> is not strictly the same as italic.

Perfect timing. I wanted to ask which alternative letter to use as %a
is taken by something (watch, perhaps?). %O/%o sounds good.

> I like the idea of %A{...} but would favour symbolic names over numbers

Another benefit of symbolic names is that zsh will know how to flip
the attribute on and off. And the UX complexity will stay pretty much
where it is now. %O and %o will work exactly like %U and %u and
similar sequences. Easy to understand. With %A{...} we would have to
explain how it interacts with the other sequences. E.g., does %u
cancel %A{4}?

Roman.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2020-01-02 19:45           ` Roman Perepelitsa
@ 2020-01-03  2:30             ` Bart Schaefer
  2020-01-03 20:28               ` Daniel Shahaf
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2020-01-03  2:30 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Oliver Kiddle, Zsh hackers list

On Thu, Jan 2, 2020 at 1:06 PM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> > %O/%o (for "oblique") would be available. I realise that an oblique font
> > is not strictly the same as italic.
>
> Perfect timing. I wanted to ask which alternative letter to use as %a
> is taken by something (watch, perhaps?). %O/%o sounds good.

Agree.  (However, the only use of %a I could find is in the zstyle
formats for VCS, which didn't seem to conflict.  There's definitely no
'a' in putpromptchar.  So we still have %A/%a if we think of something
else they're needed for.)

>
> > I like the idea of %A{...} but would favour symbolic names over numbers
>
> Another benefit of symbolic names is that zsh will know how to flip
> the attribute on and off.

I think Oliver meant symbolic names inside the braces, like
%A{oblique}, but no matter.

> With %A{...} we would have to
> explain how it interacts with the other sequences. E.g., does %u
> cancel %A{4}?

I think if we created %A{4} (which BTW I would recommend requiring at
least two digits, e.g. %A{04}) then we would have to document the
existing escapes as being shorthands for the corresponding %A forms,
so yes, %u would cancel %A{04}.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Feature request: italic style in region_highlight
  2020-01-03  2:30             ` Bart Schaefer
@ 2020-01-03 20:28               ` Daniel Shahaf
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel Shahaf @ 2020-01-03 20:28 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Thu, Jan 02, 2020 at 18:30:17 -0800:
> On Thu, Jan 2, 2020 at 1:06 PM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > > %O/%o (for "oblique") would be available. I realise that an oblique font
> > > is not strictly the same as italic.
> >
> > Perfect timing. I wanted to ask which alternative letter to use as %a
> > is taken by something (watch, perhaps?). %O/%o sounds good.
> 
> Agree.  (However, the only use of %a I could find is in the zstyle
> formats for VCS, which didn't seem to conflict.

In vcs_info one can always double the percent sign if needed.  Well, %a for one
is used in both patch-format and actionformats, so it's possible it'd have to be
doubled twice if someone wanted to use %a in its prompt meaning in patch-format.

> > With %A{...} we would have to
> > explain how it interacts with the other sequences. E.g., does %u
> > cancel %A{4}?
> 
> I think if we created %A{4} (which BTW I would recommend requiring at
> least two digits, e.g. %A{04}) then we would have to document the
> existing escapes as being shorthands for the corresponding %A forms,
> so yes, %u would cancel %A{04}.

Why would we create either %A{4} or %A{04}?  The API to script writers should
use symbolic names; the API between us and the terminal should use terminfo
rather than hardcoded escape sequences.  If anything, something like «%X{foo}»
that does the equivalent of «%{`tput foo`%}» might be worthwhile?  We could
still add an %Y/%y pair of escapes for italics but they'd be syntactic sugar
for %X{sitm} and %X{ritm} respectively.

(X, Y, and y are metasyntactic variables for the actual letters we'd use.)

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30  1:29 Feature request: italic style in region_highlight Sebastian Gniazdowski
2019-12-30 10:16 ` Roman Perepelitsa
2019-12-30 16:07   ` Bart Schaefer
2019-12-30 16:26     ` Roman Perepelitsa
2020-01-01  0:07       ` Bart Schaefer
2020-01-02 19:18         ` Oliver Kiddle
2020-01-02 19:45           ` Roman Perepelitsa
2020-01-03  2:30             ` Bart Schaefer
2020-01-03 20:28               ` Daniel Shahaf

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git