From cee21cf87c8e4dbe70fc32434916af45b4dd5468 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 15 Feb 2023 11:05:45 +0000 Subject: [PATCH] version bump, post, added --screenshot options to console run --- CHANGELOG.md | 2 +- docs/blog/images/markdown-viewer.svg | 257 +++++++++++++++++++++++++++ docs/blog/posts/release0-11-0.md | 48 +++++ examples/markdown.py | 2 + src/textual/cli/cli.py | 14 +- 5 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 docs/blog/images/markdown-viewer.svg create mode 100644 docs/blog/posts/release0-11-0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2ca4324..b96c91295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [0.11.0] - Unreleased +## [0.11.0] - 2023-02-15 ### Added diff --git a/docs/blog/images/markdown-viewer.svg b/docs/blog/images/markdown-viewer.svg new file mode 100644 index 000000000..58e077090 --- /dev/null +++ b/docs/blog/images/markdown-viewer.svg @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MarkdownApp + + + + + + + + + + Header level 6 content. +▼  Textual Markdown Browser - Demo +├── ▼  Headers▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ +│   └── ▼  This is H3 +│   └── ▼  This is H4Typography +│   └── ▼  This is H5 +│   └──  This is H6▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +├── ▼  TypographyThe usual Markdown typography is supported. The exact output depends on  +│   ┣━━  Emphasisyour terminal, although most are fairly consistent.▁▁ +│   ┣━━  Strong +│   ┣━━  StrikethroughEmphasis +│   ┗━━  Inline code▔▔▔▔▔▔▔▔ +├──  FencesEmphasis is rendered with *asterisks*, and looks like this; +├──  Quote +└──  TablesStrong +▔▔▔▔▔▔ +Use two asterisks to indicate strong which renders in bold, e.g.  +**strong** render strong. + +Strikethrough +▔▔▔▔▔▔▔▔▔▔▔▔▔ +Two tildes indicates strikethrough, e.g. ~~cross out~~ render cross out. +▂▂ +Inline code +▔▔▔▔▔▔▔▔▔▔▔ +Inline code is indicated by backticks. e.g. import this. + +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + +Fences + +▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +Fenced code blocks are introduced with three back-ticks and the optional  +parser. Here we are rendering the code in a sub-widget with syntax  +highlighting and indent guides. + +In the future I think we could add controls to export the code, copy to  +the clipboard. Heck, even run it and show the output? + + +@lru_cache(maxsize=1024) +defsplit(self,cut_x:int,cut_y:int)->tuple[Region,Region,Regi +│   """Split a region in to 4 from given x and y offsets (cuts). + T  TOC  B  Back  F  Forward  + + + diff --git a/docs/blog/posts/release0-11-0.md b/docs/blog/posts/release0-11-0.md new file mode 100644 index 000000000..869768e65 --- /dev/null +++ b/docs/blog/posts/release0-11-0.md @@ -0,0 +1,48 @@ +--- +draft: false +date: 2023-02-15 +categories: + - Release +title: "version-0110" +authors: + - willmcgugan +--- + +# Textual 0.11.0 adds a beautiful Markdown widget + +We released Textual 0.10.0 25 days ago, which is a little longer than our usual release cycle. What have we been up to? + + + +The headline feature of this release is the enhanced Markdown support. Here's a screenshot of an example: + +
+--8<-- "docs/blog/images/markdown-viewer.svg" +
+ +There are actually 2 new widgets: [Markdown](./../../widgets/markdown.md) for a simple Markdown document, and [MarkdownViewer](./../../widgets/markdown_viewer.md) which adds browser-like navigation and a table of contents. + +Textual has had support for Markdown since day one by embedding a Rich [Markdown](https://rich.readthedocs.io/en/latest/markdown.html) object (which still gives decent results)! This new widget adds dynamic controls such as scrollable code fences and tables, in addition to working links. + +In future releases I see us adding various Markdown extensions and the ability to easily embed custom widgets within the document. I'm sure there are plenty of interesting applications that could be powered by building a Markdown file with embedded widgets. + +## DataTable improvements + +There has been a lot of work on the [DataTable](../../widgets/data_table.md) widget API. We've added the ability to sort the data, which required that we introduce the concept of row and column keys. You can now reference rows / columns / cells by their coordinate or by row / column key. + +## Tree control + +The [Tree](../../api/tree.md) widget has grown a few methods to programmatically expand, collapse and toggle tree nodes. + +## Breaking changes + +There are a few breaking changes in this release. These are mostly naming and import related, which should be easy to fix if you are affected. Here's a few notable examples: + +- `Checkbox` has been renamed to `Switch`. This is because we plan to introduce complimentary `Checkbox` and `RadioButton` widgets in a future release, but we loved the look of *Switches* too much to drop them. +- We've dropped the `emit` and `emit_no_wait` methods. These methods posted message to the parent widget, but we found that made it problematic to subclass widgets. In almost all situations you want to replace these with `self.post_message` (or `self.post_message_no_wait`). + +Be sure to check the [CHANGELOG](https://github.com/Textualize/textual/blob/main/CHANGELOG.md) for the full details on potential breaking changes. + +## Join us! + +We're having fun on our [Discord server](https://discord.gg/Enf6Z3qhVr). Join us there to talk to Textualize developers and share ideas. diff --git a/examples/markdown.py b/examples/markdown.py index 59eaea9e3..1a44e70c8 100644 --- a/examples/markdown.py +++ b/examples/markdown.py @@ -1,4 +1,5 @@ from textual.app import App, ComposeResult +from textual.binding import Binding from textual.reactive import var from textual.widgets import Footer, MarkdownViewer @@ -8,6 +9,7 @@ class MarkdownApp(App): ("t", "toggle_table_of_contents", "TOC"), ("b", "back", "Back"), ("f", "forward", "Forward"), + Binding("s", "screenshot", "Screenshot", show=False), ] path = var("demo.md") diff --git a/src/textual/cli/cli.py b/src/textual/cli/cli.py index a4897bf62..16ca139cb 100644 --- a/src/textual/cli/cli.py +++ b/src/textual/cli/cli.py @@ -47,7 +47,14 @@ def console(verbose: bool, exclude: list[str]) -> None: @click.argument("import_name", metavar="FILE or FILE:APP") @click.option("--dev", "dev", help="Enable development mode", is_flag=True) @click.option("--press", "press", help="Comma separated keys to simulate press") -def run_app(import_name: str, dev: bool, press: str) -> None: +@click.option( + "--screenshot", + type=int, + default=None, + metavar="DELAY", + help="Take screenshot after DELAY seconds", +) +def run_app(import_name: str, dev: bool, press: str, screenshot: int | None) -> None: """Run a Textual app. The code to run may be given as a path (ending with .py) or as a Python @@ -73,6 +80,7 @@ def run_app(import_name: str, dev: bool, press: str) -> None: import os import sys + from asyncio import sleep from textual.features import parse_features @@ -96,6 +104,10 @@ def run_app(import_name: str, dev: bool, press: str) -> None: async def run_press_keys(pilot: Pilot) -> None: if press_keys is not None: await pilot.press(*press_keys) + if screenshot is not None: + await sleep(screenshot) + filename = pilot.app.save_screenshot() + pilot.app.exit(message=f"Saved {filename!r}") result = app.run(auto_pilot=run_press_keys)