wasi-master / rich-rst

A reStructuredText renderer for rich
https://rich-rst.readthedocs.io/en/latest/
MIT License
13 stars 3 forks source link

Truncating of text #1

Closed willmcgugan closed 2 years ago

willmcgugan commented 2 years ago

Rich-rst seems to truncate text at the right edge for some reason. I've attached a screenshot.

Let me know if you need any assistance re the Rich API.

Screen Shot 2022-02-09 at 09 25 26

.

wasi-master commented 2 years ago

yeah I would like some assistance with the rich API. The line that adds those text is this line

def visit_Text(self, node):
    style = self.console.get_style("restructuredtext.text", default="none")
    self.renderables.append(Text(node.astext().replace("\n", " "), end="", style=style))

https://github.com/wasi-master/rich-rst/blob/main/rich_rst/__init__.py#L124-L126

And the code for showing the renderables is as follows

for renderable in visitor.renderables:
    yield from console.render(renderable, options)

https://github.com/wasi-master/rich-rst/blob/main/rich_rst/__init__.py#L525-L526

So what should I do to fix that issue 🤔

wasi-master commented 2 years ago

I just tested it a bit and it seems a bit weird. The text in the blue rectangle is truncated but the text in the red one isn't

image

willmcgugan commented 2 years ago

I suspect the root of the problem is that the way you yield Text objects with end="". This may render them 0from the end, but it won't allow them to wrap.

To wrap text, you will need to extend the Text objects. i.e. by calling Text.append. Then when you have all the text you can yield it.

wasi-master commented 2 years ago

Oh I noticed another thing, in my screenshot, there isn't one text element in the blue region, there is actually 3+. one for the part before print one for the print since it is a different element (literal), and the part after the print. and therefore it isn't wrapped. in the red region it's a whole text element so it is wrapped. I'll fix this

wasi-master commented 2 years ago

So I've fixed the problem locally. Gonna release it within version 1.1.4

willmcgugan commented 2 years ago

Fantastic, Rich-CLI should pick the latest release so no update required :)

wasi-master commented 2 years ago

\:)

wasi-master commented 2 years ago

Here is the same document as above but with the fix: image