Skip to content

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

Open
@Lancern

Description

@Lancern

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions