This is an unusual suggestion, but I've tried it out in practice and it feels
really comfortable to use. I wanted to run it by you to see if it seemed
reasonable.
I found the requirement to call .render() and .render_reset() rather
verbose, particularly when trying to render several color styles in one line. I
started thinking about ways to make that more convenient, and this idea
occurred to me.
With this PR applied, Style and Reset implement Display directly,
rendering the ANSI code, without having to call .render(). That part I'm
hoping will be relatively uncontroversial; that's in the first two commits.
The more unusual part of this PR: if you set the alternate format flag, a
Style will print its reset code, instead.
The combination of the two makes it easy to use inline formats to render
styles. Here's an example of how this looks:
I'm hoping this seems reasonable. If you find the use of the alternate flag too
much, though, then as an alternative, you could drop the last two commits, and
that would still let people render codes and resets using inline styles:
This is an unusual suggestion, but I've tried it out in practice and it feels really comfortable to use. I wanted to run it by you to see if it seemed reasonable.
I found the requirement to call
.render()
and.render_reset()
rather verbose, particularly when trying to render several color styles in one line. I started thinking about ways to make that more convenient, and this idea occurred to me.With this PR applied,
Style
andReset
implementDisplay
directly, rendering the ANSI code, without having to call.render()
. That part I'm hoping will be relatively uncontroversial; that's in the first two commits.The more unusual part of this PR: if you set the alternate format flag, a
Style
will print its reset code, instead.The combination of the two makes it easy to use inline formats to render styles. Here's an example of how this looks:
I'm hoping this seems reasonable. If you find the use of the alternate flag too much, though, then as an alternative, you could drop the last two commits, and that would still let people render codes and resets using inline styles:
(This would get even easier if anstyle had a
pub const RESET: Reset = Reset;
, which I'd be happy to send in a patch for.)