Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide "quote" inline formatter #227

Closed
hadley opened this issue Mar 10, 2021 · 14 comments
Closed

Provide "quote" inline formatter #227

hadley opened this issue Mar 10, 2021 · 14 comments
Labels
feature a feature request or enhancement
Milestone

Comments

@hadley
Copy link
Member

hadley commented Mar 10, 2021

  • When colour available, colours output, and sets background colour for leading or trailing spaces
  • When colour not available, surrounds output in ".

Would want to be able to choose the quote marks and the colour.

@hadley
Copy link
Member Author

hadley commented Mar 10, 2021

@jennybc
Copy link
Member

jennybc commented Mar 13, 2021

It's also interesting to think about whether this should just be standard behaviour for some of the built-in inline styles (e.g. {.fun function_name}, {.file path/to/a/file}) or whether this "color plus no-color fallback" should just be a possible and suggested pattern for custom styles.

@hadley
Copy link
Member Author

hadley commented Mar 13, 2021

Should definitely be the case for paths, since trailing spaces are a definite real problem. Probably less so for function names.

@gaborcsardi
Copy link
Member

It is already the standard behavior AFAICT:

x <- " weird "; cli::cli_text("qwe {.path {x}} qwe")
qwe ' weird ' qwe

@jennybc
Copy link
Member

jennybc commented Mar 14, 2021

Ah, so the quotes surrounding {.file} appear conditionally, if there is leading or trailing whitespace.

Screen Shot 2021-03-14 at 10 07 07 AM

I tend to think we want the quotes unconditionally, at least in the NO_COLOR case.

I also have a specific scheme for inline style (color) and quoting that helps to make a very important distinction:

  • A Google (spread)Sheet is styled as {.file} and, when NO_COLOR, should be double-quoted
  • A (work)sheet is styled as {.field} and, when NO_COLOR, should be single-quoted

It is likely that I should create custom inline styles, give them good names, etc.

Although specific, I think my requirements are relevant to the more general question about the quoting behaviour of the inline formatters.

@gaborcsardi
Copy link
Member

I don't think we would want to quote generic <span> tags, that's too aggressive. Quoting newly added tags is pretty easy:

cli_div(theme = list(.sheet = list(before = '"', after = '"')))
sh <- "sheet"
cli_alert_success("this is a {.sheet {sh}} here")
#> v this is a "sheet" here
sh <- "      weird sheet  "
cli_alert_success("this is a {.sheet {sh}} here")
#> v this is a "      weird sheet  " here

@hadley
Copy link
Member Author

hadley commented Mar 14, 2021

I kind of like the background colour idea for paths — it seems like a nice general solution.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Mar 23, 2021
@gaborcsardi gaborcsardi added this to the 2.4.0 milestone Mar 24, 2021
@gaborcsardi
Copy link
Member

@hadley would you set the background color for the whole path, or just for the leading/trailing spaces?

@hadley
Copy link
Member Author

hadley commented Mar 25, 2021

Just the leading/trailing spaces (to make it obvious that's there's something weird going on with your path).

@jennybc
Copy link
Member

jennybc commented Mar 29, 2021

I'm still concerned that a file path has no inline styling in the NO_COLOR context (if it's free of leading/trailing whitespace). Indicated by the orange arrow below.

(And yes I'm still thinking about how I want to style spreadsheet and worksheet names, in terms of context.)

cli-inline-quoting

@gaborcsardi
Copy link
Member

I'm still concerned that a file path has no inline styling in the NO_COLOR context (if it's free of leading/trailing whitespace). Indicated by the orange arrow below.

I think usually the text indicates that it is a file or package, etc. But I don't mind always adding the quotes, that's fine as well.

@gaborcsardi
Copy link
Member

I'll re-open this to always add the quotes, and also to choose a better marker bg: set it to the same color as the foreground.

@gaborcsardi gaborcsardi reopened this Apr 12, 2021
@jennybc
Copy link
Member

jennybc commented Apr 12, 2021

always add the quotes

Do you mean always-always or ... always add quotes when NO_COLOR is non-zero?

I'm advocating for the latter, I think. I think I like the lack of quotes, when we have access to colour. But I could deal with always having quotes (that's what usethis currently does for some inline styles and it's fine).

@gaborcsardi
Copy link
Member

gaborcsardi commented Apr 12, 2021

Yeah, we can make it conditional on color support as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants