Skip to content

Commit

Permalink
option list visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Nov 6, 2024
1 parent 6c57e6f commit 1a5fbb3
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 217 deletions.
6 changes: 4 additions & 2 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
)
from textual.signal import Signal
from textual.timer import Timer
from textual.visual import SupportsTextualize
from textual.visual import SupportsTextualize, Visual
from textual.widget import AwaitMount, Widget
from textual.widgets._toast import ToastRack
from textual.worker import NoActiveWorker, get_current_worker
Expand Down Expand Up @@ -189,7 +189,9 @@
}

ComposeResult = Iterable[Widget]
RenderResult = RenderableType | SupportsTextualize
RenderResult = RenderableType | Visual | SupportsTextualize
ContentType = RenderableType | Visual | SupportsTextualize
"""Any content that can be rendered."""

AutopilotCallbackType: TypeAlias = (
"Callable[[Pilot[object]], Coroutine[Any, Any, None]]"
Expand Down
13 changes: 7 additions & 6 deletions src/textual/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ class CommandPalette(SystemModalScreen):
}
CommandPalette > .command-palette--help-text {
# text-style: dim not bold;
text-style: underline;
text-style: not bold;
color: $text-muted;
}
Expand Down Expand Up @@ -959,10 +958,12 @@ async def _gather_commands(self, search_value: str) -> None:

# We'll potentially use the help text style a lot so let's grab it
# the once for use in the loop further down.
help_style = self.get_component_rich_style(
"command-palette--help-text", partial=True
# help_style = self.get_component_rich_style(
# "command-palette--help-text", partial=True
# )
help_style = VisualStyle.from_render_styles(
self.get_component_styles("command-palette--help-text")
)

# The list to hold on to the commands we've gathered from the
# command providers.
gathered_commands: list[Command] = []
Expand Down Expand Up @@ -1025,7 +1026,7 @@ async def _gather_commands(self, search_value: str) -> None:
content = Content(prompt)
if hit.help:
prompt = content.append("\n").append(
Content.styled(hit.help, VisualStyle.from_rich_style(help_style))
Content.styled(hit.help, help_style)
)

# if hit.help:
Expand Down
24 changes: 13 additions & 11 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from textual._cells import cell_len
from textual._loop import loop_last
from textual.color import Color
from textual.css.styles import Styles
from textual.strip import Strip
from textual.visual import Style, Visual

Expand Down Expand Up @@ -128,6 +129,8 @@ class Content(Visual):

__slots__ = ["_text", "_spans", "_cell_length"]

_NORMALIZE_TEXT_ALIGN = {"start": "left", "end": "right", "justify": "full"}

def __init__(
self,
text: str,
Expand Down Expand Up @@ -162,23 +165,22 @@ def textualize(self) -> Content:
def render_strips(
self,
width: int,
*,
height: int | None,
base_style: Style = Style(),
justify: JustifyMethod = "left",
overflow: OverflowMethod = "fold",
no_wrap: bool = False,
tab_size: int = 8,
base_style: Style,
styles: Styles,
) -> list[Strip]:
horizontal_align = styles.text_align
justify = self._NORMALIZE_TEXT_ALIGN.get(horizontal_align, horizontal_align)
lines = self.wrap(
width,
justify=justify,
overflow=overflow,
no_wrap=no_wrap,
tab_size=tab_size,
justify=justify, # type: ignore[arg-type]
overflow="fold",
no_wrap=False,
tab_size=8,
)
if height is not None:
lines = lines[:height]
base_style = base_style + Style.from_render_styles(styles)
return [
Strip(line.render_segments(base_style), line.cell_length) for line in lines
]
Expand Down Expand Up @@ -876,5 +878,5 @@ def highlight_regex(
print(lines)
print("x" * 40)
for line in lines:
segments = Segments(line.render_segments(ANSI_DEFAULT))
segments = Segments(line.render_segments(ANSI_DEFAULT, end="\n"))
print(segments)
6 changes: 3 additions & 3 deletions src/textual/css/_style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ def __get__(
"""Get the string property, or the default value if it's not set.
Args:
obj: The ``Styles`` object.
objtype: The ``Styles`` class.
obj: The `Styles` object.
objtype: The `Styles` class.
Returns:
The string property value.
Expand All @@ -823,7 +823,7 @@ def __set__(self, obj: StylesBase, value: EnumType | None = None):
"""Set the string property and ensure it is in the set of allowed values.
Args:
obj: The ``Styles`` object.
obj: The `Styles` object.
value: The string value to set the property to.
Raises:
Expand Down
2 changes: 1 addition & 1 deletion src/textual/demo/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ProjectInfo:
"Darren Burns",
"https://posting.sh/",
"""Posting is an HTTP client, not unlike Postman and Insomnia. As a TUI application, it can be used over SSH and enables efficient keyboard-centric workflows. """,
"4.7k",
"5.0k",
),
ProjectInfo(
"Memray",
Expand Down
2 changes: 2 additions & 0 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ def get_component_styles(self, *names: str) -> RenderStyles:
Returns:
A Styles object.
"""

styles = RenderStyles(self, Styles(), Styles())

for name in names:
if name not in self._component_styles:
raise KeyError(f"No {name!r} key in COMPONENT_CLASSES")
Expand Down
Loading

0 comments on commit 1a5fbb3

Please sign in to comment.