Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for locally viewing the source of a PEP #17

Merged
merged 22 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bef0dd1
:sparkles: Add an API call for downloading the source of a PEP
davep Jan 28, 2025
cd68210
:sparkles: Add the core framework of a PEP source viewer screen
davep Jan 28, 2025
495f94b
:lipstick: Improve the look of the PEP viewer
davep Jan 28, 2025
dd2bcc3
:hammer: Have API.pep_file return a Path rather than a string
davep Jan 28, 2025
b204d51
:hammer: Simplify the CSS for the PEP viewer
davep Jan 28, 2025
6611517
:sparkles: Add support for a cache location
davep Jan 28, 2025
1b8f02c
:art: Tidy the order of the exports
davep Jan 28, 2025
073589a
:sparkles: Add a cache facility to the PEP source viewer screen
davep Jan 28, 2025
f32faa4
:books: Add mention of the cache files to the "File locations" in README
davep Jan 28, 2025
29e963d
:hammer: Only set loading in one place
davep Jan 29, 2025
4f2fd6a
:hammer: Swap to using a ScrollableContainer
davep Jan 29, 2025
d533a82
:hammer: Swap to using a read-only TextArea to view the PEP source
davep Jan 29, 2025
94f1c7c
:sparkles: Add a text viewing widget
davep Jan 29, 2025
8019258
:sparkles: Swap the PEP source viewer over to the TextViewer widget
davep Jan 29, 2025
cc75e1b
:books: Update the ChangeLog
davep Jan 29, 2025
b816a14
:lipstick: Remove the line highlight from the TextViewer widget
davep Jan 29, 2025
a5a96c9
:sparkles: Add some movement tweaks to the TextViewer
davep Jan 29, 2025
94330a6
:sparkles: Add all the options for copying
davep Jan 29, 2025
19ef679
:hammer: Correctly identify the start and end of the text to view
davep Jan 29, 2025
759b67d
:books: Fix a documentation typo
davep Jan 29, 2025
03ea80a
:lipstick: Improve the cosmetics of the PEP source viewer
davep Jan 29, 2025
86414da
:lipstick: Use the accent colour to highlight the keys in buttons
davep Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Swap the PEP source viewer over to the TextViewer widget
davep committed Jan 29, 2025
commit 801925832f5041ac86e218f3c2e2dd46903e1fa4
18 changes: 11 additions & 7 deletions src/peplum/app/screens/pep_viewer.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
# Local imports.
from ...peps import API
from ..data import PEP, cache_dir
from ..widgets import TextViewer


##############################################################################
@@ -34,17 +35,14 @@ class PEPViewer(ModalScreen[None]):
border: panel $border;
}

#text {
TextViewer {
color: $text-muted;
height: 1fr;
background: transparent;
scrollbar-background: $panel;
scrollbar-background-hover: $panel;
scrollbar-background-active: $panel;
border: none;
&:focus {
color: $text;
border: none;
}
}

@@ -61,7 +59,7 @@ class PEPViewer(ModalScreen[None]):
}
"""

BINDINGS = [("escape", "close"), ("ctrl+r", "refresh")]
BINDINGS = [("escape", "close"), ("ctrl+r", "refresh"), ("ctrl+c", "copy")]

def __init__(self, pep: PEP) -> None:
"""Initialise the dialog.
@@ -77,8 +75,9 @@ def compose(self) -> ComposeResult:
"""Compose the dialog's content."""
with Vertical() as dialog:
dialog.border_title = f"PEP{self._pep.number}"
yield TextArea(id="text", read_only=True)
yield TextViewer()
with Horizontal(id="buttons"):
yield Button("Copy [dim]\\[^c][/]", id="copy")
yield Button("Refresh [dim]\\[^r][/]", id="refresh")
yield Button("Close [dim]\\[Esc][/]", id="close")

@@ -96,7 +95,7 @@ async def _download_text(self) -> None:
attempting to download the PEP, this local copy will be used
instead.
"""
(text := self.query_one("#text", TextArea)).loading = True
(text := self.query_one(TextViewer)).loading = True
pep_source = ""

if self._cache_name.exists():
@@ -141,5 +140,10 @@ def action_refresh(self) -> None:
pass
self._download_text()

@on(Button.Pressed, "#copy")
async def action_copy(self) -> None:
"""Copy PEP text to the clipboard."""
await self.query_one(TextArea).run_action("copy")


### pep_viewer.py ends here