Skip to content

Commit

Permalink
Merge pull request #94 from darrenburns/upgrade-textual
Browse files Browse the repository at this point in the history
Upgrade textual
  • Loading branch information
darrenburns authored Aug 26, 2024
2 parents 3e7adc1 + fa484e0 commit 9fa19b5
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 352 deletions.
Binary file modified .coverage
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = [
"pyyaml==6.0.1",
"pydantic-settings==2.3.4",
"python-dotenv==1.0.1",
"textual[syntax]==0.76.0",
"textual[syntax]==0.77.0",
"textual-autocomplete==3.0.0a9",
]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ sniffio==1.3.1
# via httpx
syrupy==4.6.1
# via pytest-textual-snapshot
textual==0.76.0
textual==0.77.0
# via posting
# via pytest-textual-snapshot
# via textual-autocomplete
Expand Down
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rich==13.7.1
sniffio==1.3.1
# via anyio
# via httpx
textual==0.76.0
textual==0.77.0
# via posting
# via textual-autocomplete
textual-autocomplete==3.0.0a9
Expand Down
3 changes: 2 additions & 1 deletion src/posting/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from textual.command import CommandPalette
from textual.css.query import NoMatches
from textual.events import Click
from textual.keys import format_key
from textual.reactive import Reactive, reactive
from textual.app import App, ComposeResult
from textual.binding import Binding
Expand Down Expand Up @@ -170,7 +171,7 @@ def compose(self) -> ComposeResult:
yield CollectionBrowser(collection=self.collection)
yield RequestEditor()
yield ResponseArea()
yield Footer()
yield Footer(show_command_palette=False)

async def send_request(self) -> None:
self.url_bar.clear_events()
Expand Down
32 changes: 20 additions & 12 deletions src/posting/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class PostingProvider(Provider):
@property
def commands(
self,
) -> tuple[tuple[str, IgnoreReturnCallbackType, str], ...]:
) -> tuple[tuple[str, IgnoreReturnCallbackType, str, bool], ...]:
app = self.posting
screen = self.screen

commands_to_show: list[tuple[str, IgnoreReturnCallbackType, str]] = [
commands_to_show: list[tuple[str, IgnoreReturnCallbackType, str, bool]] = [
*self.get_theme_commands(),
("app: quit", app.action_quit, "Quit Posting"),
("app: quit", app.action_quit, "Quit Posting", True),
]

from posting.app import MainScreen
Expand All @@ -30,6 +30,7 @@ def commands(
"layout: vertical",
partial(app.command_layout, "vertical"),
"Change layout to vertical",
True,
),
)
elif screen.layout == "vertical":
Expand All @@ -38,6 +39,7 @@ def commands(
"layout: horizontal",
partial(app.command_layout, "horizontal"),
"Change layout to horizontal",
True,
),
)

Expand All @@ -48,16 +50,19 @@ def commands(
"view: reset",
partial(screen.maximize_section, None),
"Reset section sizes to default",
True,
)
expand_request_command = (
"view: expand request",
partial(screen.maximize_section, "request"),
"Expand the request section",
True,
)
expand_response_command = (
"view: expand response",
partial(screen.maximize_section, "response"),
"Expand the response section",
True,
)
if maximized == "request":
commands_to_show.extend([reset_command, expand_response_command])
Expand All @@ -73,6 +78,7 @@ def commands(
"view: toggle collection browser",
screen.action_toggle_collection_browser,
"Toggle the collection browser",
True,
),
)

Expand All @@ -84,12 +90,13 @@ async def discover(self) -> Hits:
Yields:
Commands that can be discovered.
"""
for name, runnable, help_text in self.commands:
yield DiscoveryHit(
name,
runnable,
help=help_text,
)
for name, runnable, help_text, show_discovery in self.commands:
if show_discovery:
yield DiscoveryHit(
name,
runnable,
help=help_text,
)

async def search(self, query: str) -> Hits:
"""Handle a request to search for commands that match the query.
Expand All @@ -101,7 +108,7 @@ async def search(self, query: str) -> Hits:
Command hits for use in the command palette.
"""
matcher = self.matcher(query)
for name, runnable, help_text in self.commands:
for name, runnable, help_text, _ in self.commands:
if (match := matcher.match(name)) > 0:
yield Hit(
match,
Expand All @@ -112,17 +119,18 @@ async def search(self, query: str) -> Hits:

def get_theme_commands(
self,
) -> tuple[tuple[str, IgnoreReturnCallbackType, str], ...]:
) -> tuple[tuple[str, IgnoreReturnCallbackType, str, bool], ...]:
posting = self.posting
return tuple(self.get_theme_command(theme) for theme in posting.themes)

def get_theme_command(
self, theme_name: str
) -> tuple[str, IgnoreReturnCallbackType, str]:
) -> tuple[str, IgnoreReturnCallbackType, str, bool]:
return (
f"theme: {theme_name}",
partial(self.posting.command_theme, theme_name),
f"Set the theme to {theme_name}",
False,
)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/posting/help_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def compose(self) -> ComposeResult:
", ".join(
binding.key_display
if binding.key_display
else self.app.get_key_display(key)
else self.app.get_key_display(binding)
for binding in bindings
),
style="bold",
Expand Down
2 changes: 1 addition & 1 deletion src/posting/widgets/collection/new_request_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def compose(self) -> ComposeResult:

yield Button.success("Create request", id="create-button")

yield Footer()
yield Footer(show_command_palette=False)

def action_close_screen(self) -> None:
self.dismiss(None)
Expand Down
Loading

0 comments on commit 9fa19b5

Please sign in to comment.