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

[Feature Request] Support formatting parameters in pattern placeholders #56

Open
Lancern opened this issue Dec 27, 2023 · 0 comments
Open
Labels
enhancement New feature or request
Milestone

Comments

@Lancern
Copy link
Collaborator

Lancern commented Dec 27, 2023

spdlog supports specifying text alignment in its pattern flags, see https://github.com/gabime/spdlog/wiki/3.-Custom-formatting#aligning:

  • %8l requires right alignment and will expand to info;
  • %-8l requires left alignment and will expand to info ;
  • %=8l requires center alignment and will expand to info .

Besides, an additional ! can be used to truncate the expanded result if it's too wide:

  • %3!l, %-3!l, and %=3!l will expand to inf.

This feature can be neat sometimes and maybe we could also support this. We may follow the convention of format! and propose the following new pattern placeholder syntax:

placeholder := '{' NAME [ ':' format_spec ] '}'
format_spec := [ [fill] align ] [ ['.'] width ]
fill := CHAR
align := INT
width := INT

Some examples:

  • {level:8} and {level:<8} will expand to info (left alignment, pad with spaces);
  • {level:-<8} will expand to info---- (left alignment, pad with -);
  • {level:>8} will expand to info (right alignment, pad with spaces);
  • {level:->8} will expand to ----info (right alignment, pad with -);
  • {level:^8} will expand to info (center alignment, pad with spaces);
  • {level:-^8} will expand to --info-- (center alignment, pad with -);
  • {level:.3} will expand to inf (left alignment, truncate field to 3 characters long).
@Lancern Lancern added the enhancement New feature or request label Dec 27, 2023
@SpriteOvO SpriteOvO added this to the v0.5.0 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants