Skip to content

Can We "Defend Against" Multiple Styles at Once? #816

Description

@GregYannes

Background

This is a spinoff of my original question on Stack Overflow, regarding the style_no_*() family.

Every style_*() function has a style_no_*() pair, which defends its argument from taking on the style.

When applying several style_no_*() functions to text, only the latest (or outermost) "defense" actually succeeds:

"Example text" |>
  style_no_strikethrough() |> style_no_italic() |>
  style_strikethrough()    |> style_italic()    |> style_bold()

<cli_ansi_string>
[1]Example text


This is also true for compound styles, via combine_ansi_styles().

sty_0 <- combine_ansi_styles(
  style_no_italic,
  style_no_strikethrough
)

sty_1 <- combine_ansi_styles(
  style_italic,
  style_bold,
  style_strikethrough
)

"Example text" |> sty_0() |> sty_1()

<cli_ansi_string>
[1]Example text


It seems each defense must be applied immediately before it is needed.

"Example text" |>
  style_no_italic() |> style_italic() |>
  style_no_strikethrough() |> style_strikethrough() |>
  style_bold()

<cli_ansi_string>
[1]Example text

Question

Is this an inherent limitation of ANSI sequences? Or should I request this as a feature? Or is it actually a bug?

Thanks — Greg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions