Replies: 9 comments
-
|
We found the following entry in the FAQ which you may find helpful: Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review. This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others). This is an automated reply, generated by FAQtory |
Beta Was this translation helpful? Give feedback.
-
|
A workaround would be to iterate over a from rich.style import Style
from textual.strip import Strip
class ...
def render_line(self, y: int) -> Strip:
# strip from superclass
strip = super().render_line(y)
# my custom style I want to see applied
my_style = Style(bgcolor="red")
# iterate over the segments of the strip and
# apply styles to them
segments = [seg for seg in strip]
segments = Segment.apply_style(segments, post_style=my_style)
# recombine to newly styled strip
return Strip(segments)However, this functionality of iterating over a |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I'd like to work on this. I'll submit a PR shortly. |
Beta Was this translation helpful? Give feedback.
-
|
@jbdyn What is it that you are rendering, and what are you attempting to change in your |
Beta Was this translation helpful? Give feedback.
-
|
@willmcgugan Sure! I inherit from the The API is mostly there and works, so I can update the content from both local and remote, but I also need to render the remote cursor positions. For that, my current solution is to implement my own I wanted to do this with # from `TextArea` widget
strip = super().render_line(y)
# define style for remote cursor
cursor_style = Style(bgcolor=cursor_color)
# cut the current strips at the remote cursor position
strips = strip.divide([cursor_start, cursor_end])
# apply remote cursor style to remote cursor cell;
strips[1] = strips[1].apply_style(cursor_style) # <-- does not change the bgcolor
# rejoin for rendering
strip = Strip.join(strips)As it could be relevant in this context, in the future, I also would like to not just color a cursor position but the whole selection between the anchor and head of a remote cursor. If it helps, here is the code. |
Beta Was this translation helpful? Give feedback.
-
|
I think you would be better off doing this in the |
Beta Was this translation helpful? Give feedback.
-
|
Sounded nice and I tried, but I ran into three problems:
|
Beta Was this translation helpful? Give feedback.
-
|
Consider Strips to be the Textual equivalent of a bitmap. You want to add your cursors at an earlier stage where you can work with a more semantic layer. Have a look at Try copying that method to a subclass and add your cursor code. I'd also accept a PR to add a method to provide a convenient hook. |
Beta Was this translation helpful? Give feedback.
-
|
The local cursor/selection is also drawn in the As I basically want to do the exact same for multiple cursors: Would you also be interested in a PR which puts the selection drawing code in a public method, say, A style hook could then still be implemented, but that does not exactly hit my case. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I wanted to redefine the
render_linemethod of a widget to alter the style of strips returned by the superclass method.However, my
Styles are not applied when callingStrip.apply_style.The problem is that
Strip.apply_styledoes not expose thepost_styleparameter to be passed torich'sSegment.apply_style. Its docstring in turn saysWithout the
post_styleparameter inStrip.apply_style, I have no way to overwrite the style of aStripif an internalSegmentcomes with its own style.Since I am not a collaborator in this project: A fix is available on my fork at https://github.com/jbdyn/textual/tree/apply-post-style with commit 594265f.
If this patch is not suitable: What would be the alternative if I wanted to change a
Stripreturned by the superclass'srender_linemethod?Beta Was this translation helpful? Give feedback.
All reactions