-
Hi, I am trying to write a file manager with textual. When file name is long and doesn't fit in the content size, I would like to render using "..." (three periods) or "…" (single character which contains three dots, I don't know the name of this character). In case of HTML CSS, text-overflow: ellipsis can be used. Can I use similar feature on Textual, either similar CSS expression for Static widget, or even with some Python coding (custom Widget)? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There isn't currently a method of doing this via Textual's CSS, although believe it's something we'd like to do. Meanwhile though, if I'm understanding your requirement correctly, I think you should be able to do what you're after with a combination of from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Static
from rich.text import Text
class Box( Container ):
DEFAULT_CSS = "Box { border: solid red; height: auto; background: #555; }"
def compose(self) -> ComposeResult:
yield Static(
Text( "Happiness, free, for everyone, and let no one be forgotten!", no_wrap=True, overflow="ellipsis" )
)
class OverflowApp( App[ None ] ):
def compose(self) -> ComposeResult:
for n in range( 16 ):
yield ( box := Box() )
box.styles.width = ( 1 + n ) * 4
if __name__ == "__main__":
OverflowApp().run() giving this sort of effect: |
Beta Was this translation helpful? Give feedback.
There isn't currently a method of doing this via Textual's CSS, although believe it's something we'd like to do. Meanwhile though, if I'm understanding your requirement correctly, I think you should be able to do what you're after with a combination of
Static
from Textual andText
fromRich
, like this: