Can We "Defend Against" Multiple Styles at Once?

Open
#816 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
r
Domain
cli

Research direction

Start with the style_no_*() functions and combine_ansi_styles() entry points described in the issue, then reproduce the chained examples. Determine whether ANSI sequences can preserve multiple defenses at once; done means the demonstrated italic and strikethrough defenses both remain effective when later styles are applied.

Written by the indexing model from the issue text.

Description

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

Dominant language
R
Stars
726
Forks
94
Avg merge
3h 35m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cli

All issues in r-lib/cli

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.