Skip to content

Commit c9c59c3

Browse files
authored
🔀 Merge pull request #1 from davep/general-refresh
General refresh
2 parents 9521ff4 + bc46cfc commit c9c59c3

File tree

8 files changed

+272
-220
lines changed

8 files changed

+272
-220
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# textual-mandelbrot ChangeLog
22

3+
## v0.8.0
4+
5+
**Released: 2024-03-10**
6+
7+
- Bumped minimum Textual version to v0.52.1.
8+
- Made the command palette commands appear when opening the command palette.
9+
310
## v0.7.0
411

512
**Released: 2024-01-07**

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spackage: # Create a source package for the library
7575
$(build) -s
7676

7777
.PHONY: packagecheck
78-
packagecheck: package # Check the packaging.
78+
packagecheck: package spackage # Check the packaging.
7979
$(twine) check dist/*
8080

8181
.PHONY: testdist

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ textual-canvas = "*"
99
black = "*"
1010

1111
[dev-packages]
12-
pylint = "*"
1312
mypy = "*"
1413
twine = "*"
1514
black = "*"
1615
pre-commit = "*"
1716
build = "*"
17+
pylint = "*"
1818

1919
[requires]
20-
python_version = "3.10"
20+
python_version = "3.12"

Pipfile.lock

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

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@ terminal.
1212

1313
## Installing
1414

15+
### pipx
16+
1517
The package can be installed using [`pipx`](https://pypa.github.io/pipx/):
1618

1719
```sh
1820
$ pipx install textual-mandelbrot
1921
```
2022

23+
### Homebrew
24+
25+
The package is available via Homebrew. Use the following commands to install:
26+
27+
```sh
28+
$ brew tap davep/homebrew
29+
$ brew install textual-mandelbrot
30+
```
31+
32+
## Running
33+
2134
Once installed you should be able to run the command `mandelexp` and the
2235
application will run.
2336

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ classifiers =
2222
Programming Language :: Python :: 3.9
2323
Programming Language :: Python :: 3.10
2424
Programming Language :: Python :: 3.11
25+
Programming Language :: Python :: 3.12
2526
Topic :: Terminals
2627
Topic :: Software Development :: Libraries
2728
Typing :: Typed
@@ -36,7 +37,7 @@ packages = find:
3637
platforms = any
3738
include_package_data = True
3839
install_requires =
39-
textual>=0.47.1
40+
textual>=0.52.1
4041
textual-canvas
4142
python_requires = >=3.8
4243

textual_mandelbrot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__credits__ = ["Dave Pearson"]
88
__maintainer__ = "Dave Pearson"
99
__email__ = "davep@davep.org"
10-
__version__ = "0.7.0"
10+
__version__ = "0.8.0"
1111
__licence__ = "MIT"
1212

1313
##############################################################################

textual_mandelbrot/commands.py

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
##############################################################################
44
# Python imports.
55
from functools import partial
6+
from typing import Callable, Iterator
67

78
##############################################################################
89
# Textual imports.
9-
from textual.command import Hit, Hits, Provider
10+
from textual.color import Color
11+
from textual.command import DiscoveryHit, Hit, Hits, Provider
1012

1113
##############################################################################
1214
# Local imports.
@@ -18,43 +20,25 @@
1820
class MandelbrotCommands(Provider):
1921
"""A source of command palette commands for the Mandelbrot widget."""
2022

21-
async def search(self, query: str) -> Hits:
22-
"""Handle a request to search for system commands that match the query.
23-
24-
Args:
25-
user_input: The user input to be matched.
26-
27-
Yields:
28-
Command hits for use in the command palette.
29-
"""
30-
31-
# Nothing in here makes sense if the user isn't current on a
32-
# Mandelbrot set.
33-
if not isinstance(self.focused, Mandelbrot):
34-
return
35-
36-
# Get a fuzzy matcher for looking for hits.
37-
matcher = self.matcher(query)
23+
PREFIX = "Mandelbrot: "
24+
"""Prefix that is common to all the commands."""
3825

39-
# Give all commands a common prefix.
40-
prefix = "Mandelbrot: "
41-
42-
# Spin out some commands for setting the colours.
26+
@classmethod
27+
def _colour_commands(cls) -> Iterator[tuple[str, Callable[[int, int], Color], str]]:
28+
"""The colour commands."""
4329
for colour, source in (
4430
("default", default_map),
4531
("blue/brown", blue_brown_map),
4632
("green", shades_of_green),
4733
):
48-
colour = f"{prefix}Set the colour map to {colour} "
49-
match = matcher.match(colour)
50-
if match:
51-
yield Hit(
52-
match,
53-
matcher.highlight(colour),
54-
partial(self.focused.set_colour_source, source),
55-
help=f"Set the Mandelbrot colour palette to {colour}",
56-
)
34+
yield (
35+
f"{cls.PREFIX}Set the colour map to {colour} ",
36+
source,
37+
f"Set the Mandelbrot colour palette to {colour}",
38+
)
5739

40+
@classmethod
41+
def _action_commands(cls) -> Iterator[tuple[str, str, str]]:
5842
# Spin out some commands based around available actions.
5943
for command, action, help_text in (
6044
(
@@ -92,7 +76,69 @@ async def search(self, query: str) -> Hits:
9276
"Remove detail from the Mandelbrot set (will run faster)",
9377
),
9478
):
95-
command = f"{prefix}{command}"
79+
yield (f"{cls.PREFIX}{command}", action, help_text)
80+
81+
async def discover(self) -> Hits:
82+
"""Handle a request to discover commands.
83+
84+
Yields:
85+
Command discovery hits for the command palette.
86+
"""
87+
88+
# Nothing in here makes sense if the user isn't current on a
89+
# Mandelbrot set.
90+
if not isinstance(self.focused, Mandelbrot):
91+
return
92+
93+
# Spin out some commands for setting the colours.
94+
for command, source, help_text in self._colour_commands():
95+
yield DiscoveryHit(
96+
command,
97+
partial(self.focused.set_colour_source, source),
98+
command,
99+
help_text,
100+
)
101+
102+
# Spin out the action commands.
103+
for command, action, help_text in self._action_commands():
104+
yield DiscoveryHit(
105+
command,
106+
partial(self.focused.run_action, action),
107+
command,
108+
help_text,
109+
)
110+
111+
async def search(self, query: str) -> Hits:
112+
"""Handle a request to search for system commands that match the query.
113+
114+
Args:
115+
user_input: The user input to be matched.
116+
117+
Yields:
118+
Command hits for use in the command palette.
119+
"""
120+
121+
# Nothing in here makes sense if the user isn't current on a
122+
# Mandelbrot set.
123+
if not isinstance(self.focused, Mandelbrot):
124+
return
125+
126+
# Get a fuzzy matcher for looking for hits.
127+
matcher = self.matcher(query)
128+
129+
# Spin out some commands for setting the colours.
130+
for command, source, help_text in self._colour_commands():
131+
match = matcher.match(command)
132+
if match:
133+
yield Hit(
134+
match,
135+
matcher.highlight(command),
136+
partial(self.focused.set_colour_source, source),
137+
help=help_text,
138+
)
139+
140+
# Spin out the action commands.
141+
for command, action, help_text in self._action_commands():
96142
match = matcher.match(command)
97143
if match:
98144
yield Hit(

0 commit comments

Comments
 (0)