Replies: 1 comment
-
here's a very simple attempt def print(before, after):
from rich.console import Console, Group
from rich.panel import Panel
from rich.text import Text
from more_itertools import peekable
import parsy
console = Console()
diff = unified_diff(
before.split("\n"),
after.split("\n"),
fromfile="before",
tofile="after",
)
diff = peekable(diff)
if not diff:
return
any_chars = parsy.any_char.at_least(1).concat()
pp = (
(
parsy.peek(parsy.string("@@"))
>> any_chars.map(lambda x: Text(text=x, style="bold magenta"))
)
| (
parsy.string("-")
>> any_chars.map(lambda x: Text(text=x, style="bold red"))
)
| (
parsy.string("+")
>> any_chars.map(lambda x: Text(text=x, style="bold green"))
)
| (parsy.string(" ") >> parsy.any_char.at_least(1).concat().map(Text))
| (
parsy.string("?")
>> any_chars.map(lambda x: Text(text=x, style="bold magenta"))
)
| (any_chars.map(Text))
)
diffs = seq(diff).drop(2).map(pp.parse)
console.print(
Panel(
Group(*diffs),
)
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to render HTML within rich itself?
Use case: rendering the difference between two strings.
An easy way to do this would be to use difflib but it generates a string of html.
Curious if it's possible to render that html within rich itself without having to parse it.
Beta Was this translation helpful? Give feedback.
All reactions