Shopify / Shopify/cli-ui

[formatter] How to escape end expressions to handle JSON braces?

Open
#586 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
57
Avg merge
2h 55m
Merged PRs (30d)
2

Description

Is there a way to color text and escape any braces in it?

Problem: ending braces aren't getting color or they're getting removed:

hash = {wtv: 3}
CLI::UI.puts("{{magenta:#{hash}}}") # last brace is not colored
hash2 = {wtv: {key: 3}}
CLI::UI.puts("{{magenta:#{hash2}}}") # last 2 braces are missing: "{wtv: {key: 3"
Image

Here's one work-around I found:

CLI::UI.puts("#{CLI::UI::Color::MAGENTA.code}#{hash}", format: false)

Update: The work-around isn't as easy to do for command formatting, unless you wanna assume that commands are always cyan:

CLI::UI.puts("{{command:run { {json}}}}") # omits the ending "}}"
CLI::UI.puts("\e[#{CLI::UI::Formatter::SGR_MAP['command']}mrun { {json}}", format: false) # works
Image

Update 2:
Using colorize also helps.

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.

Research direction

Start at CLI::UI.puts and reproduce the formatter behavior with the hash and command examples in the issue. Trace how end expressions are parsed and determine how literal braces should be escaped or preserved; done means the closing braces remain present and receive the intended color.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.