Skip to content

Feature Request: Add support for measurement units in ReprHighlighter #4049

@poullakkos

Description

@poullakkos

Currently, ReprHighlighter handles numeric literals well, but it treats trailing measurement units (like GB, ms, %) as plain text. This makes technical logs and performance metrics harder to scan quickly, as the unit doesn't share the same visual importance or distinct styling as the number it belongs to.

I've developed an enhancement for the number regex in ReprHighlighter to include an optional number_unit named group. This allows Rich to recognize and style common units (TB, GB, MB, KB, B, ms, s, m, h, %) when they follow a numeric literal.

Proposed Regex:

r"(?P<number_unit>(?<!\w)\-?(?:0[xX][0-9a-fA-F_]+|0b[01_]+|(?:(?:\d{1,3}(?:[_,]\d{3})+)|\d+)(?:\.\d*)?(?:e[-+]?\d+)?)\s?(?:TB|GB|MB|KB|B|ms|h|s|m|%))"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions