You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: writing a custom hi lighter could resolve this, but I feel that the built in regex should accept
Describe the bug
The default highlighting for numbers in rich does not support separators in numbers or binary formatting.
Here is an example of printing numbers with rich.print
Here we see that the hex is colored up to first occurrence of underscore _, decimal is colored in-between the commas , and not colored when the separator is underscore _, binary numbers are not colored as well.
With possible enhancements to make the groups for hex and binary only accept groups of 4 like the decimal does 3 now.
Another enhancement would be to allow internationalization of the . and , in the decimal.
There minor fix for the regex is that it no longer has an extra unnamed match on the exponent of a floating point number.
see re.findall output below.
I'm sure that I may have missed a nuance from the positive lookbehind assertion on the match.
Describe the bug
The default highlighting for numbers in rich does not support separators in numbers or binary formatting.
Here is an example of printing numbers with
rich.print
rich.print(f"{0x1234:#08x} {0x123456:#08_x} {0b110011001100:#b} {0b111110100101:#_b} {1234567890:,d} {123456789:d}")
Here we see that the hex is colored up to first occurrence of underscore
_
, decimal is colored in-between the commas,
and not colored when the separator is underscore_
, binary numbers are not colored as well.Perhaps the following regex for number.
r"(?P<number>(?:0[xX][0-9a-fA-F_]+\b)|(?:0b[01_]+\b)|(?:(?<!\w)\-?(?:(?:(?:[0-9]{1,2}[,_])?(?:[0-9]{3}[,_])*(?<=[,_])[0-9]{3})|[0-9]+)(?:\.?[0-9]*(?:e[-+]?\d+)?)?\b))"
With possible enhancements to make the groups for hex and binary only accept groups of 4 like the decimal does 3 now.
Another enhancement would be to allow internationalization of the
.
and,
in the decimal.There minor fix for the regex is that it no longer has an extra unnamed match on the exponent of a floating point number.
see
re.findall
output below.I'm sure that I may have missed a nuance from the positive lookbehind assertion on the match.
Platform
Click to expand
What platform (Mac) are you running on?
Mac OS 14
What terminal software are you using?
iTerm2
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
If you're using Rich in a terminal:
The text was updated successfully, but these errors were encountered: