zsh-users
 help / color / mirror / code / Atom feed
* Color in completions
@ 2016-01-29 13:13 Sebastian Gniazdowski
  2016-01-29 22:45 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-01-29 13:13 UTC (permalink / raw)
  To: Zsh Users

Hello
In my script I complete Github's paths, like "psprint/plugin-name".
Would like to give color to the two components of the path. Simple use
of escape code like in:

$'this \x1b[0;32mIs a test'

doesn't work – the completions displayed print information on the
escape code instead of interpreting the code:

this\ $'\033'\[0\;32mIs\ a\ test

I guess there is no way to change that?

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-01-29 13:13 Color in completions Sebastian Gniazdowski
@ 2016-01-29 22:45 ` Bart Schaefer
  2016-01-31 15:38   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2016-01-29 22:45 UTC (permalink / raw)
  To: Zsh Users

On Jan 29,  2:13pm, Sebastian Gniazdowski wrote:
}
} In my script I complete Github's paths, like "psprint/plugin-name".
} Would like to give color to the two components of the path.

You can get color in completion listings with the complist module,
see "man zshmodules" or "info zsh 'The zsh/complist Module'".  In
particular this reference to $ZLS_COLORS:

  The leading-equals form also allows different parts of the displayed
  strings to be colored differently.  For this, the pattern has to use the
  `(#b)' globbing flag and pairs of parentheses surrounding the parts of
  the strings that are to be colored differently. ...

To color what's inserted onto the command line by completion, you
have to set the region_highlight array, which is what z-sy-h does.


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

* Re: Color in completions
  2016-01-29 22:45 ` Bart Schaefer
@ 2016-01-31 15:38   ` Sebastian Gniazdowski
  2016-01-31 17:39     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-01-31 15:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 29 January 2016 at 23:45, Bart Schaefer <schaefer@brasslantern.com> wrote:
> You can get color in completion listings with the complist module,
> see "man zshmodules" or "info zsh 'The zsh/complist Module'".  In
> particular this reference to $ZLS_COLORS:
>
>   The leading-equals form also allows different parts of the displayed
>   strings to be colored differently.  For this, the pattern has to use the
>   `(#b)' globbing flag and pairs of parentheses surrounding the parts of
>   the strings that are to be colored differently. ...

Managed to do this. Had to:
1. Figure out to use _wanted instead of only compadd
2. Figure out what pattern to give to zstyle:

zstyle ':completion:*:zplugin:*:argument-rest' list-colors
'=(#b)(*)/(*)==1;35=1;33'

When I display $curcontext within _zplugin (after adding -C to
_arguments), it shows: :complete:zplugin:argument-rest. I wonder why
do I need the additional ":*:" before "argument-rest" ? Or even the
first one.

https://github.com/psprint/zplugin/blob/master/_zplugin

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-01-31 15:38   ` Sebastian Gniazdowski
@ 2016-01-31 17:39     ` Bart Schaefer
  2016-01-31 18:52       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2016-01-31 17:39 UTC (permalink / raw)
  To: Zsh Users

On Jan 31,  4:38pm, Sebastian Gniazdowski wrote:
} Subject: Re: Color in completions
}
} On 29 January 2016 at 23:45, Bart Schaefer <schaefer@brasslantern.com> wrote:
} > You can get color in completion listings with the complist module,
} > see "man zshmodules" or "info zsh 'The zsh/complist Module'".
} 
} Managed to do this. Had to:
} 1. Figure out to use _wanted instead of only compadd

Actually I think it's _description that you need rather than _wanted,
but calling _wanted gets you there via _all_labels ...

Or you could just assign ZLS_COLORS yourself instead of using a style,
I think, but calling _wanted is preferable.

} 2. Figure out what pattern to give to zstyle:
} 
} zstyle ':completion:*:zplugin:*:argument-rest' list-colors
} '=(#b)(*)/(*)==1;35=1;33'
} 
} When I display $curcontext within _zplugin (after adding -C to
} _arguments), it shows: :complete:zplugin:argument-rest. I wonder why
} do I need the additional ":*:" before "argument-rest" ? Or even the
} first one.

I don't know why you need the second one.  You shouldn't.  What you
should need is a :* at the end, for the "tag" slot (see below).

You need the first one because the string ":completion:" with colons
at both ends is prefixed to $curcontext for style lookups.

 The context string always consists of a fixed set of fields, separated
 by colons and with a leading colon before the first.  Fields which are
 not yet known are left empty, but the surrounding colons appear anyway.
 The fields are always in the order
 :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:TAG.

So in your zstyle above --

    Lookup context      Your pattern
    --------------      ------------
    completion          completion
    FUNCTION:COMPLETER  *
    COMMAND             zplugin
    ARGUMENT            *
    TAG                 argument-rest

I would have expected "argument-rest" to match the ARGUMENT position
rather than the TAG position, so:

  zstyle ':completion:*:zplugin:argument-rest:*' list-colors \
      '=(#b)(*)/(*)==1;35=1;33'

What does ctl+x h (_complete_help) show if you use that instead of tab?


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

* Re: Color in completions
  2016-01-31 17:39     ` Bart Schaefer
@ 2016-01-31 18:52       ` Sebastian Gniazdowski
  2016-02-01  7:49         ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-01-31 18:52 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 31 January 2016 at 18:39, Bart Schaefer <schaefer@brasslantern.com> wrote:
>  The fields are always in the order
>  :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:TAG.
>
> So in your zstyle above --
>
>     Lookup context      Your pattern
>     --------------      ------------
>     completion          completion
>     FUNCTION:COMPLETER  *
>     COMMAND             zplugin
>     ARGUMENT            *
>     TAG                 argument-rest
>
> I would have expected "argument-rest" to match the ARGUMENT position
> rather than the TAG position, so:
>
>   zstyle ':completion:*:zplugin:argument-rest:*' list-colors \
>       '=(#b)(*)/(*)==1;35=1;33'

This works

> What does ctl+x h (_complete_help) show if you use that instead of tab?

tags in context :completion::complete:zplugin::
    argument-rest  (_arguments _zplugin)

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-01-31 18:52       ` Sebastian Gniazdowski
@ 2016-02-01  7:49         ` Sebastian Gniazdowski
  2016-02-01 14:53           ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-01  7:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 31 January 2016 at 19:52, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> tags in context :completion::complete:zplugin::
>     argument-rest  (_arguments _zplugin)

That was after "zplg unload". After "zplg" it's:

tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)
    commands    (_describe _zplugin)

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-02-01  7:49         ` Sebastian Gniazdowski
@ 2016-02-01 14:53           ` Bart Schaefer
  2016-02-01 16:25             ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2016-02-01 14:53 UTC (permalink / raw)
  To: Zsh Users

On Feb 1,  8:49am, Sebastian Gniazdowski wrote:
} Subject: Re: Color in completions
}
} On 31 January 2016 at 19:52, Sebastian Gniazdowski
} <sgniazdowski@gmail.com> wrote:
} > tags in context :completion::complete:zplugin::
} >     argument-rest  (_arguments _zplugin)
} 
} That was after "zplg unload". After "zplg" it's:
} 
} tags in context :completion::complete:zplugin::
}     argument-1  (_arguments _zplugin)
}     commands    (_describe _zplugin)

Your best bet then is just to use

    zstyle ':completion:*:zplugin:*' list-colors ...


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

* Re: Color in completions
  2016-02-01 14:53           ` Bart Schaefer
@ 2016-02-01 16:25             ` Sebastian Gniazdowski
  2016-02-01 21:31               ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-01 16:25 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 1 February 2016 at 15:53, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Feb 1,  8:49am, Sebastian Gniazdowski wrote:
> } Subject: Re: Color in completions
> }
> } On 31 January 2016 at 19:52, Sebastian Gniazdowski
> } <sgniazdowski@gmail.com> wrote:
> } > tags in context :completion::complete:zplugin::
> } >     argument-rest  (_arguments _zplugin)
> }
> } That was after "zplg unload". After "zplg" it's:
> }
> } tags in context :completion::complete:zplugin::
> }     argument-1  (_arguments _zplugin)
> }     commands    (_describe _zplugin)
>
> Your best bet then is just to use
>
>     zstyle ':completion:*:zplugin:*' list-colors ...

I already had (#mark):
zstyle ':completion:*:zplugin:*:argument-rest' list-colors
'=(#b)(*)/(*)==1;35=1;33'

Comparing that to your proposition:
zstyle ':completion:*:zplugin:*' list-colors ...
zstyle ':completion:*:zplugin:*:argument-rest' list-colors ...

it seems that the zstyle #mark is correct, it just matches more – also
the "argument-rest", which is expected, because plugin names may
appear after a command

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-02-01 16:25             ` Sebastian Gniazdowski
@ 2016-02-01 21:31               ` Bart Schaefer
  2016-02-02 11:21                 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2016-02-01 21:31 UTC (permalink / raw)
  To: Zsh Users

On Feb 1,  5:25pm, Sebastian Gniazdowski wrote:
} Subject: Re: Color in completions
}
} On 1 February 2016 at 15:53, Bart Schaefer <schaefer@brasslantern.com> wrote:
} > On Feb 1,  8:49am, Sebastian Gniazdowski wrote:
} > }
} > } tags in context :completion::complete:zplugin::
} > }     argument-1  (_arguments _zplugin)
} > }     commands    (_describe _zplugin)

Hmm, I get (after editing _zplugin to add -C):

burner% zplg
tags in context :completion::complete:zplg::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zplg:argument-1:
    commands  (_zplugin)

burner% zplg unload
tags in context :completion::complete:zplg::
    argument-rest  (_arguments _zplugin)
tags in context :completion::complete:zplg:argument-rest:
    plugins  (_zplugin)

What's different about the _zplugin you're using from the one in github?

I'd forgotten that argument-N and argument-rest can appear in both the
ARGUMENT position and TAG position in the standard completion context.

Also if you look through the _complete_debug output, the context used
is really :completion::complete:zplg:argument-rest:argument-rest so
you need something in the ARGUMENT.  I wonder why _complete_help gets
that wrong, but that's why both :argument-rest:* and :*:argument-rest
work.

} >     zstyle ':completion:*:zplugin:*' list-colors ...
} 
} I already had (#mark):
} zstyle ':completion:*:zplugin:*:argument-rest' list-colors
} '=(#b)(*)/(*)==1;35=1;33'
} 
} Comparing that to your proposition:
} zstyle ':completion:*:zplugin:*' list-colors ...
} zstyle ':completion:*:zplugin:*:argument-rest' list-colors ...
} 
} it seems that the zstyle #mark is correct, it just matches more - also
} the "argument-rest", which is expected, because plugin names may
} appear after a command

Your #mark style is more specific than my suggestion.  That means it
matches neither the argument-1 tag nor the command and plugins tags.


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

* Re: Color in completions
  2016-02-01 21:31               ` Bart Schaefer
@ 2016-02-02 11:21                 ` Sebastian Gniazdowski
  2016-02-02 17:49                   ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-02 11:21 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 1 February 2016 at 22:31, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Feb 1,  5:25pm, Sebastian Gniazdowski wrote:
> } Subject: Re: Color in completions
> }
> } On 1 February 2016 at 15:53, Bart Schaefer <schaefer@brasslantern.com> wrote:
> } > On Feb 1,  8:49am, Sebastian Gniazdowski wrote:
> } > }
> } > } tags in context :completion::complete:zplugin::
> } > }     argument-1  (_arguments _zplugin)
> } > }     commands    (_describe _zplugin)
>
> Hmm, I get (after editing _zplugin to add -C):
>
> burner% zplg
> tags in context :completion::complete:zplg::
>     argument-1  (_arguments _zplugin)
> tags in context :completion::complete:zplg:argument-1:
>     commands  (_zplugin)

The "zplg" is weird. Again to compare what I have:

% zplg
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)
    commands    (_describe _zplugin)

When I add -C to _arguments (btw, when to use -C?):

% zpl
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zplugin:argument-1:
    commands  (_describe _zplugin)

> burner% zplg unload
> tags in context :completion::complete:zplg::
>     argument-rest  (_arguments _zplugin)
> tags in context :completion::complete:zplg:argument-rest:
>     plugins  (_zplugin)

With -C:

# zplg unload
tags in context :completion::complete:zplugin::
    argument-rest  (_arguments _zplugin)
tags in context :completion::complete:zplugin:argument-rest:
    plugins  (_zplugin)

> What's different about the _zplugin you're using from the one in github?

No difference. BTW. I above pasted what zsh-5.0.8 and zsh-5.2 gives
(the same outputs)

> I'd forgotten that argument-N and argument-rest can appear in both the
> ARGUMENT position and TAG position in the standard completion context.
>
> Also if you look through the _complete_debug output, the context used
> is really :completion::complete:zplg:argument-rest:argument-rest so
> you need something in the ARGUMENT.  I wonder why _complete_help gets
> that wrong, but that's why both :argument-rest:* and :*:argument-rest
> work.

What zstyle would you do to handle zpl, zplg aliases? I could provide
multiple Zstyles so that no user will be left without colors.

> } >     zstyle ':completion:*:zplugin:*' list-colors ...
> }
> } I already had (#mark):
> } zstyle ':completion:*:zplugin:*:argument-rest' list-colors
> } '=(#b)(*)/(*)==1;35=1;33'
> }
> } Comparing that to your proposition:
> } zstyle ':completion:*:zplugin:*' list-colors ...
> } zstyle ':completion:*:zplugin:*:argument-rest' list-colors ...
> }
> } it seems that the zstyle #mark is correct, it just matches more - also
> } the "argument-rest", which is expected, because plugin names may
> } appear after a command
>
> Your #mark style is more specific than my suggestion.  That means it
> matches neither the argument-1 tag nor the command and plugins tags.

I wish I could understand all this better.

Best regards,
Sebastian Gniazdowski


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

* Re: Color in completions
  2016-02-02 11:21                 ` Sebastian Gniazdowski
@ 2016-02-02 17:49                   ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2016-02-02 17:49 UTC (permalink / raw)
  To: Zsh Users

On Feb 2, 12:21pm, Sebastian Gniazdowski wrote:
} Subject: Re: Color in completions
}
} > Hmm, I get (after editing _zplugin to add -C):
} >
} > burner% zplg
} > tags in context :completion::complete:zplg::
} >     argument-1  (_arguments _zplugin)
} > tags in context :completion::complete:zplg:argument-1:
} >     commands  (_zplugin)
} 
} The "zplg" is weird.

Sorry, my bad.  Some other stuff I was fooling with leaked in.  This is
the effect of the COMPLETE_ALIASES option:

burner% setopt completealiases 
burner% zpl
tags in context :completion::complete:zpl::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zpl:argument-1:
    commands  (_zplugin)

If I make sure completaliases is off, then without -C/curcontext I get:

burner% zplg
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)

(note no "commands") and with -C/curcontext I get:

burner% zplg
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zplugin:argument-1:
    commands  (_zplugin)

} Again to compare what I have:
} 
} % zplg
} tags in context :completion::complete:zplugin::
}     argument-1  (_arguments _zplugin)
}     commands    (_describe _zplugin)

The difference must be with zstyle, e.g., the completer style -- I am
(now that I got rid of completealiases) testing with the absolute
minimum setup after "zsh -f" so I have only one zstyle:

burner% zstyle -L
zstyle ':completion:*:zplugin:*:argument-rest' list-colors '=(#b)(*)/(*)==1;35=1;33'
burner% 

} When I add -C to _arguments (btw, when to use -C?):

Doc:

     The option -C tells _arguments to modify the curcontext parameter
     for an action of the form `->STATE'.  This is the standard
     parameter used to keep track of the current context.  Here it (and
     not the context array) should be made local to the calling
     function to avoid passing back the modified value and should be
     initialised to the current value at the start of the function:

          local curcontext="$curcontext"

     This is useful where it is not possible for multiple states to be
     valid together.

As I understand this, the point of -C is to create distinct zstyle
contexts for different ->state targets, so that the context can be
referenced in the caller of _arguments (and otherwise downstream) after
_arguments has returned.  So e.g. in _zplugin, in the "case $state"
block, when _wanted is called it sees the context set by _arguments -C
instead of the context in which _zplugin started.

} What zstyle would you do to handle zpl, zplg aliases? I could provide
} multiple Zstyles so that no user will be left without colors.

I'm not sure what you mean by this -- normally you would provide only
the tag names, it's up to the user to decide on the context.

If you mean what settings you should suggest, you could try:

    zstyle ':completion:*:zpl*:*:argument-rest' list-colors ...

} > Your #mark style is more specific than my suggestion.  That means it
} > matches neither the argument-1 tag nor the command and plugins tags.
} 
} I wish I could understand all this better.

Zstyles are a little weird because they're backwards from typical usage.
Normally the user would supply a fixed string and the code would have a
pattern that it compared.  With zstyle, the code has the fixed (though
incrementally constructed) string [the context] and the user supplies
the pattern, so that the same style can apply to multiple contexts.

So for completion the more colons and fewer wildcards that appear in
the user's zstyle commands, the more specifically those settings apply.

(It's potentially important to remember that the colons are specific to
the use of zstyle in compsys and have no special significance to the
internals of the zstyle command.)

-- 
Barton E. Schaefer


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

end of thread, other threads:[~2016-02-02 17:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-29 13:13 Color in completions Sebastian Gniazdowski
2016-01-29 22:45 ` Bart Schaefer
2016-01-31 15:38   ` Sebastian Gniazdowski
2016-01-31 17:39     ` Bart Schaefer
2016-01-31 18:52       ` Sebastian Gniazdowski
2016-02-01  7:49         ` Sebastian Gniazdowski
2016-02-01 14:53           ` Bart Schaefer
2016-02-01 16:25             ` Sebastian Gniazdowski
2016-02-01 21:31               ` Bart Schaefer
2016-02-02 11:21                 ` Sebastian Gniazdowski
2016-02-02 17:49                   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).