mirror of
https://github.com/Textualize/textual-serve.git
synced 2025-10-17 02:50:37 +03:00
Opening URL new_tab parameter
This commit is contained in:
@@ -1 +1 @@
|
||||
3.12.3
|
||||
3.11.8
|
||||
|
||||
@@ -12,7 +12,7 @@ from textual.containers import VerticalScroll
|
||||
from textual.widgets import Input, Markdown
|
||||
|
||||
|
||||
class DictionaryApp(App):
|
||||
class DictionaryApp(App[None]):
|
||||
"""Searches a dictionary API as-you-type."""
|
||||
|
||||
CSS_PATH = "dictionary.tcss"
|
||||
|
||||
21
examples/open_link.py
Normal file
21
examples/open_link.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from textual import on
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Button
|
||||
|
||||
|
||||
class OpenLink(App[None]):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Button("Visit the Textual docs", id="open-link-same-tab")
|
||||
yield Button("Visit the Textual docs in a new tab", id="open-link-new-tab")
|
||||
|
||||
@on(Button.Pressed)
|
||||
def open_link(self, event: Button.Pressed) -> None:
|
||||
self.open_url(
|
||||
"https://textual.textualize.io",
|
||||
new_tab=event.button.id == "open-link-new-tab",
|
||||
)
|
||||
|
||||
|
||||
app = OpenLink()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
6
examples/serve_any.py
Normal file
6
examples/serve_any.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import sys
|
||||
from textual_serve.server import Server
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = Server(sys.argv[1])
|
||||
server.serve(debug=False)
|
||||
4
examples/serve_open_link.py
Normal file
4
examples/serve_open_link.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from textual_serve.server import Server
|
||||
|
||||
server = Server("python open_link.py")
|
||||
server.serve(debug=False)
|
||||
@@ -6,10 +6,10 @@ authors = [
|
||||
{ name = "Will McGugan", email = "will@textualize.io" }
|
||||
]
|
||||
dependencies = [
|
||||
"textual>=0.66.0",
|
||||
"aiohttp>=3.9.5",
|
||||
"aiohttp-jinja2>=1.6",
|
||||
"jinja2>=3.1.4",
|
||||
"textual>=0.66.0",
|
||||
]
|
||||
readme = "README.md"
|
||||
requires-python = ">= 3.8"
|
||||
@@ -20,7 +20,9 @@ build-backend = "hatchling.build"
|
||||
|
||||
[tool.rye]
|
||||
managed = true
|
||||
dev-dependencies = []
|
||||
dev-dependencies = [
|
||||
"httpx", # required to run the dictionary example
|
||||
]
|
||||
|
||||
[tool.hatch.metadata]
|
||||
allow-direct-references = true
|
||||
|
||||
@@ -16,12 +16,24 @@ aiohttp-jinja2==1.6
|
||||
# via textual-serve
|
||||
aiosignal==1.3.1
|
||||
# via aiohttp
|
||||
anyio==4.4.0
|
||||
# via httpx
|
||||
attrs==23.2.0
|
||||
# via aiohttp
|
||||
certifi==2024.7.4
|
||||
# via httpcore
|
||||
# via httpx
|
||||
frozenlist==1.4.1
|
||||
# via aiohttp
|
||||
# via aiosignal
|
||||
h11==0.14.0
|
||||
# via httpcore
|
||||
httpcore==1.0.5
|
||||
# via httpx
|
||||
httpx==0.27.0
|
||||
idna==3.7
|
||||
# via anyio
|
||||
# via httpx
|
||||
# via yarl
|
||||
jinja2==3.1.4
|
||||
# via aiohttp-jinja2
|
||||
@@ -45,7 +57,10 @@ pygments==2.18.0
|
||||
# via rich
|
||||
rich==13.7.1
|
||||
# via textual
|
||||
textual==0.66.0
|
||||
sniffio==1.3.1
|
||||
# via anyio
|
||||
# via httpx
|
||||
textual==0.74.0
|
||||
# via textual-serve
|
||||
typing-extensions==4.12.2
|
||||
# via textual
|
||||
|
||||
@@ -45,7 +45,7 @@ pygments==2.18.0
|
||||
# via rich
|
||||
rich==13.7.1
|
||||
# via textual
|
||||
textual==0.66.0
|
||||
textual==0.74.0
|
||||
# via textual-serve
|
||||
typing-extensions==4.12.2
|
||||
# via textual
|
||||
|
||||
@@ -23,9 +23,9 @@ class AppService:
|
||||
self,
|
||||
command: str,
|
||||
*,
|
||||
write_bytes: Callable[[bytes], Awaitable],
|
||||
write_str: Callable[[str], Awaitable],
|
||||
close: Callable[[], Awaitable],
|
||||
write_bytes: Callable[[bytes], Awaitable[None]],
|
||||
write_str: Callable[[str], Awaitable[None]],
|
||||
close: Callable[[], Awaitable[None]],
|
||||
debug: bool = False,
|
||||
) -> None:
|
||||
self.command = command
|
||||
@@ -35,7 +35,7 @@ class AppService:
|
||||
self.debug = debug
|
||||
|
||||
self._process: Process | None = None
|
||||
self._task: asyncio.Task | None = None
|
||||
self._task: asyncio.Task[None] | None = None
|
||||
self._stdin: asyncio.StreamWriter | None = None
|
||||
self._exit_event = asyncio.Event()
|
||||
|
||||
@@ -269,6 +269,19 @@ class AppService:
|
||||
data: Encoded meta data.
|
||||
"""
|
||||
meta_data = json.loads(data)
|
||||
|
||||
if meta_data["type"] == "exit":
|
||||
await self.remote_close()
|
||||
match meta_data["type"]:
|
||||
case "exit":
|
||||
await self.remote_close()
|
||||
case "open_url":
|
||||
payload = json.dumps(
|
||||
[
|
||||
"open_url",
|
||||
{
|
||||
"url": meta_data["url"],
|
||||
"new_tab": meta_data["new_tab"],
|
||||
},
|
||||
]
|
||||
)
|
||||
await self.remote_write_str(payload)
|
||||
case _:
|
||||
pass
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user