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

[core] TermCtl: A custom parser to replace color and mode placeholders in print/format #248

Merged
merged 7 commits into from
Jul 14, 2024

Conversation

rbrich
Copy link
Owner

@rbrich rbrich commented Jul 9, 2024

Do not delegate to fmt. There is a regression in fmt 11, which broke that - named placeholders cannot be mixed with automatically indexed ones. Although I think this should be allowed, using the named args for the TermCtl color placeholders was basically a hack. A custom parser will be more flexible and allow more freedom regarding the syntax.

The new placeholders are processed purely in runtime. Unknown placeholders are left untouched. Compile-time checking is still possible, but that doesn't seem as important feature. Actual replacing by escape sequences must be done in runtime, as it depends on what is attached to the output stream (tty or pipe).

New syntax:

<bold>bold text<normal>
<b>shortcut attrs<n>
<red><@blue>red text on blue background<n>
<*white>intense white text<n>
  • Escaping for the opening <, e.g. "\<"
  • Drop the fg:, make it default - e.g. <red>
  • Drop the bg:, use different syntax for that, e.g. <@blue> (blue background), <red@blue> (red text on blue background)

…sing a custom parser

Do not delegate to fmt. There is a regression in fmt 11, which broke that - named placeholders cannot be mixed with automatically indexed ones.
Although I think this should be allowed, using the named args for the TermCtl color placeholders was basically a hack. A custom parser will be more flexible and allow more freedom regarding the syntax.

The new placeholders are processed purely in runtime. Unknown placeholders are left untouched. Compile-time checking is still possible, but that doesn't seem as important feature. Actual replacing by escape sequences must be done in runtime, as it depends on what is attached to the output stream (tty or pipe).
@rbrich rbrich marked this pull request as ready for review July 14, 2024 17:21
@rbrich rbrich enabled auto-merge July 14, 2024 18:13
@rbrich rbrich merged commit 274949e into master Jul 14, 2024
23 checks passed
@rbrich rbrich deleted the termctl-custom-format branch July 14, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant