From f2f13eacf050470208141885625da5f2755b17eb Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 7 Oct 2022 18:00:35 +0100 Subject: [PATCH] proof reading --- docs/examples/app/question03.py | 6 +++--- docs/guide/app.md | 19 +++++++++---------- docs/guide/index.md | 2 +- docs/guide/styles.md | 14 +++++++------- src/textual/cli/cli.py | 10 +++++++++- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/examples/app/question03.py b/docs/examples/app/question03.py index 41ad0f349..777e5a9eb 100644 --- a/docs/examples/app/question03.py +++ b/docs/examples/app/question03.py @@ -5,9 +5,9 @@ from textual.widgets import Static, Button class QuestionApp(App[str]): CSS = """ Screen { - layout: table; - table-size: 2; - table-gutter: 2; + layout: grid; + grid-size: 2; + grid-gutter: 2; padding: 2; } #question { diff --git a/docs/guide/app.md b/docs/guide/app.md index b1edc3ae2..1689895ef 100644 --- a/docs/guide/app.md +++ b/docs/guide/app.md @@ -46,7 +46,7 @@ One such event is the *mount* event which is sent to an application after it ent !!! info - You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. We will cover the details in [events](./events.md). + You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. See [events](./events.md) for details. Another such event is the *key* event which is sent when the user presses a key. The following example contains handlers for both those events: @@ -65,19 +65,18 @@ The key event handler (`on_key`) has an `event` parameter which will receive a [ It is unusual (but not unprecedented) for a method's parameters to affect how it is called. Textual accomplishes this by inspecting the method prior to calling it. -For some events contains additional information. In the case of [Key][textual.events.Key] it will contain the key that was pressed. - -The `on_key` method above changes the background color if any of the keys from ++0++ to ++9++ are pressed. +Some events contain additional information you can inspect in the handler. The [Key][textual.events.Key] event has a `key` attribute which is the name of the key that was pressed. The `on_key` method above uses this attribute to change the background color if any of the keys from ++0++ to ++9++ are pressed. ### Async events -Textual is powered by Python's [asyncio](https://docs.python.org/3/library/asyncio.html) framework which uses the `async` and `await` keywords to coordinate events. +Textual is powered by Python's [asyncio](https://docs.python.org/3/library/asyncio.html) framework which uses the `async` and `await` keywords. -Textual knows to *await* your event handlers if they are coroutines (i.e. prefixed with the `async` keyword). +Textual knows to *await* your event handlers if they are coroutines (i.e. prefixed with the `async` keyword). Regular functions are generally fine unless you plan on integrating other async libraries (such as [httpx](https://www.python-httpx.org/) for reading data from the internet). -!!! note +!!! tip - Don't worry if you aren't familiar with the async programming in Python. You can build many apps without using them. + For a friendly introduction to async programming in Python, see FastAPI's [concurrent burgers](https://fastapi.tiangolo.com/async/) article. + ## Widgets @@ -89,13 +88,13 @@ Widgets can be as simple as a piece of text, a button, or a fully-fledge compone To add widgets to your app implement a [`compose()`][textual.app.App.compose] method which should return an iterable of Widget instances. A list would work, but it is convenient to yield widgets, making the method a *generator*. -The following example imports a builtin Welcome widget and yields it from compose. +The following example imports a builtin Welcome widget and yields it from `App.compose()`. ```python title="widgets01.py" --8<-- "docs/examples/app/widgets01.py" ``` -When you run this code, Textual will *mount* the Welcome widget which contains a Markdown content area and a button: +When you run this code, Textual will *mount* the Welcome widget which contains Markdown content and a button: ```{.textual path="docs/examples/app/widgets01.py"} ``` diff --git a/docs/guide/index.md b/docs/guide/index.md index 10c6e3a0f..412a09b13 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -1,6 +1,6 @@ # Textual Guide -Welcome to the Textual Guide! An in-depth reference on how to build app with Textual. +Welcome to the Textual Guide! An in-depth reference on how to build apps with Textual. ## Example code diff --git a/docs/guide/styles.md b/docs/guide/styles.md index 30c50057c..99457a078 100644 --- a/docs/guide/styles.md +++ b/docs/guide/styles.md @@ -62,12 +62,12 @@ In addition to color names, you can also use any of the following ways of expres - RGB hex colors starts with a `#` followed by three pairs of one or two hex digits; one for the red, green, and blue color components. For example, `#f00` is an intense red color, and `#9932CC` is *dark orchid*. - RGB decimal color start with `rgb` followed by a tuple of three numbers in the range 0 to 255. For example `rgb(255,0,0)` is intense red, and `rgb(153,50,204)` is *dark orchid*. -- HSL colors start with `hsl` followed by a angle between 0 and 360 and two percentage values, representing Hue, Saturation and Lightness. For example `hsl(0,100%,50%)` is intense red and `hsl(280,60%,49%)` is *dark orchid* +- HSL colors start with `hsl` followed by a angle between 0 and 360 and two percentage values, representing Hue, Saturation and Lightness. For example `hsl(0,100%,50%)` is intense red and `hsl(280,60%,49%)` is *dark orchid*. The background and color styles also accept a [Color][textual.color.Color] object which can be used to create colors dynamically. -The following example adds three widgets and sets color styles. +The following example adds three widgets and sets their color styles. ```python title="colors01.py" hl_lines="16-19" --8<-- "docs/examples/guide/styles/colors01.py" @@ -103,7 +103,7 @@ Notice that an alpha of 0.1 the background almost matches the screen, but at 1.0 ## Dimensions -Widgets occupy a rectangular region of the screen, which may be as small as a single character or as large as the screen (potentially *larger* if [scrolling](#) is enabled). +Widgets occupy a rectangular region of the screen, which may be as small as a single character or as large as the screen (potentially *larger* if [scrolling](../styles/overflow.md) is enabled). ### Box Model @@ -146,7 +146,7 @@ Let's set the height to auto and see what happens. --8<-- "docs/examples/guide/styles/dimensions02.py" ``` -If you run this you will see the height of the widget now grows to accommodate the full text.: +If you run this you will see the height of the widget now grows to accommodate the full text: ```{.textual path="docs/examples/guide/styles/dimensions02.py"} ``` @@ -195,7 +195,7 @@ Let's look at an example. We will create two widgets, one with a height of `"2fr --8<-- "docs/examples/guide/styles/dimensions04.py" ``` -The total `fr` units for height is 3. The first widget will have a screen height of two thirds because its height style is set to `2fr`. The second widget's height styles is `1fr` so its screen height will be a third. Here's what that looks like. +The total `fr` units for height is 3. The first widget will have a screen height of two thirds because its height style is set to `2fr`. The second widget's height styles is `1fr` so its screen height will be one third. Here's what that looks like. ```{.textual path="docs/examples/guide/styles/dimensions04.py"} ``` @@ -222,7 +222,7 @@ Notice the additional space around the text: ```{.textual path="docs/examples/guide/styles/padding01.py"} ``` -You can also set padding to a tuple of two integers which will apply padding to the top/bottom and left/right edges. The following example sets padding to `(2, 4)` which adds two rows to the top and bottom of the widget, and 4 columns to the left and right of the widget. +You can also set padding to a tuple of *two* integers which will apply padding to the top/bottom and left/right edges. The following example sets padding to `(2, 4)` which adds two rows to the top and bottom of the widget, and 4 columns to the left and right of the widget. ```python title="padding02.py" hl_lines="22" --8<-- "docs/examples/guide/styles/padding02.py" @@ -233,7 +233,7 @@ Compare the output of this example to the previous example: ```{.textual path="docs/examples/guide/styles/padding02.py"} ``` -You can also set padding to a tuple of four values which applies padding to each edge individually. The first value is the padding for the top of the widget, followed by the right of the widget, then bottom, then left. +You can also set padding to a tuple of *four* values which applies padding to each edge individually. The first value is the padding for the top of the widget, followed by the right of the widget, then bottom, then left. ### Border diff --git a/src/textual/cli/cli.py b/src/textual/cli/cli.py index 7b856b689..13e167411 100644 --- a/src/textual/cli/cli.py +++ b/src/textual/cli/cli.py @@ -86,7 +86,15 @@ def run_app(import_name: str, dev: bool, press: str) -> None: sys.exit(1) press_keys = press.split(",") if press else None - app.run(press=press_keys) + result = app.run(press=press_keys) + + if result is not None: + from rich.console import Console + from rich.pretty import Pretty + + console = Console() + console.print("[b]The app returned:") + console.print(Pretty(result)) @run.command("borders")