Skip to content

Commit f2ae8f1

Browse files
authored
🔀 Merge pull request #20 from davep/copy-command
Add an app command for copying a command line to clipboard
2 parents cf102a7 + b6c7060 commit f2ae8f1

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
values. ([#11](https://github.com/davep/complexitty/issues/11))
1111
- Changed the display of the X/Y location so that the precision adapts to
1212
the zoom level. ([#14](https://github.com/davep/complexitty/issues/14))
13+
- Added `CopyCommandLineToClipboard`.
14+
([#20](https://github.com/davep/complexitty/pull/20))
1315

1416
## v0.2.0
1517

src/complexitty/commands/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SetColourToShadesOfGreen,
1212
SetColourToShadesOfRed,
1313
)
14-
from .main import Quit
14+
from .main import CopyCommandLineToClipboard, Quit
1515
from .navigation import (
1616
GoMiddle,
1717
GoTo,
@@ -42,6 +42,7 @@
4242
##############################################################################
4343
# Exports.
4444
__all__ = [
45+
"CopyCommandLineToClipboard",
4546
"DecreaseMaximumIteration",
4647
"DecreaseMultibrot",
4748
"GreatlyDecreaseMaximumIteration",

src/complexitty/commands/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ class Quit(Command):
1414
SHOW_IN_FOOTER = True
1515

1616

17+
##############################################################################
18+
class CopyCommandLineToClipboard(Command):
19+
"""Copy the command line for the current view to the clipboard"""
20+
21+
BINDING_KEY = "c"
22+
23+
1724
### main.py ends here

src/complexitty/providers/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
##############################################################################
1313
# Local imports.
1414
from ..commands import (
15+
CopyCommandLineToClipboard,
1516
DecreaseMaximumIteration,
1617
DecreaseMultibrot,
1718
GoMiddle,
@@ -55,6 +56,7 @@ def commands(self) -> CommandHits:
5556
Yields:
5657
The commands for the command palette.
5758
"""
59+
yield CopyCommandLineToClipboard()
5860
yield ChangeTheme()
5961
yield DecreaseMaximumIteration()
6062
yield DecreaseMultibrot()

src/complexitty/screens/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
##############################################################################
2323
# Local imports.
2424
from ..commands import (
25+
CopyCommandLineToClipboard,
2526
DecreaseMaximumIteration,
2627
DecreaseMultibrot,
2728
GoMiddle,
@@ -75,6 +76,7 @@ class Main(EnhancedScreen[None]):
7576
ChangeTheme,
7677
Quit,
7778
# Everything else.
79+
CopyCommandLineToClipboard,
7880
DecreaseMaximumIteration,
7981
DecreaseMultibrot,
8082
GoMiddle,
@@ -253,5 +255,20 @@ async def action_go_to_command(self) -> None:
253255
severity="error",
254256
)
255257

258+
def action_copy_command_line_to_clipboard_command(self) -> None:
259+
"""Copy the current view as a command, to the clipboard."""
260+
plot = self.query_one(Mandelbrot)
261+
command = (
262+
f"complexitty "
263+
f"--x-position={plot.x_position} "
264+
f"--y-position={plot.y_position} "
265+
f"--zoom={plot.zoom} "
266+
f"--max-iteration={plot.max_iteration} "
267+
f"--multibrot={plot.multibrot} "
268+
f"--colour-map={plot.colour_map.__name__}"
269+
)
270+
self.app.copy_to_clipboard(command)
271+
self.notify(command, title="Copied")
272+
256273

257274
### main.py ends here

0 commit comments

Comments
 (0)