Skip to content

Commit 10c2d20

Browse files
authored
Merge pull request #41 from Textualize/space-page
added space to page
2 parents 804626c + dfe2e00 commit 10c2d20

6 files changed

Lines changed: 88 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Added space key to page down to pager
13+
14+
### Changed
15+
16+
- Change how code blocks in markdown are rendered (remove border, adding padding)
17+
18+
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.5.1...HEAD

poetry.lock

Lines changed: 29 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ classifiers = [
2323

2424
[tool.poetry.dependencies]
2525
python = "^3.7"
26-
rich = "^11.2.0"
26+
rich = "^12.0.0"
2727
click = "^8.0.0"
2828
requests = "^2.0.0"
2929
textual = "^0.1.15"
30-
rich-rst = "^1.0.0"
30+
rich-rst = "^1.1.7"
3131

3232
[tool.poetry.dev-dependencies]
33-
black = "21.12b0"
34-
mypy = "^0.931"
33+
black = "21.1.0"
34+
mypy = "0.941"
3535

3636
[build-system]
3737
requires = ["poetry-core>=1.0.0"]

src/rich_cli/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def print_usage() -> None:
558558
on_error("unable to read json", error)
559559

560560
elif resource_format == MARKDOWN:
561-
from rich.markdown import Markdown
561+
from .markdown import Markdown
562562

563563
markdown_data, lexer = read_resource(resource, lexer)
564564
renderable = Markdown(markdown_data, hyperlinks=hyperlinks)

src/rich_cli/markdown.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Any
2+
3+
from rich.console import Console, ConsoleOptions, RenderResult
4+
from rich.markdown import Markdown, TextElement
5+
from rich.padding import Padding
6+
from rich.syntax import Syntax
7+
8+
9+
class CodeBlock(TextElement):
10+
"""A code block with syntax highlighting."""
11+
12+
style_name = "markdown.code_block"
13+
14+
@classmethod
15+
def create(cls, markdown: "Markdown", node: Any) -> "CodeBlock":
16+
node_info = node.info or ""
17+
lexer_name = node_info.partition(" ")[0]
18+
return cls(lexer_name or "default", markdown.code_theme)
19+
20+
def __init__(self, lexer_name: str, theme: str) -> None:
21+
self.lexer_name = lexer_name
22+
self.theme = theme
23+
24+
def __rich_console__(
25+
self, console: Console, options: ConsoleOptions
26+
) -> RenderResult:
27+
code = str(self.text).rstrip()
28+
syntax = Syntax(code, self.lexer_name, theme=self.theme, word_wrap=True)
29+
yield Padding(syntax, (0, 4))
30+
31+
32+
Markdown.elements["code_block"] = CodeBlock

src/rich_cli/pager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def __init__(
5858
async def on_load(self, event: events.Load) -> None:
5959
await self.bind("q", "quit", "Quit")
6060

61+
async def on_key(self, event: events.Key) -> None:
62+
if event.key == " ":
63+
self.body.page_down()
64+
6165
async def on_mount(self, event: events.Mount) -> None:
6266
self.body = body = ScrollView(auto_width=True)
6367

0 commit comments

Comments
 (0)