From c75622c4859f9edfaf259ab95cf70df400f3ea02 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 23 Apr 2025 15:09:20 +0100 Subject: [PATCH 1/2] :sparkles: Add an app command for copying a command line to clipboard This adds a command that will copy a command line call to complexitty, complete with appropriate command line switches, such that the current view should be recreated (or at least as close as possible). Closes #12. --- ChangeLog.md | 1 + src/complexitty/commands/__init__.py | 3 ++- src/complexitty/commands/main.py | 7 +++++++ src/complexitty/providers/main.py | 2 ++ src/complexitty/screens/main.py | 17 +++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4dc6af6..72b83f2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,6 +10,7 @@ values. ([#11](https://github.com/davep/complexitty/issues/11)) - Changed the display of the X/Y location so that the precision adapts to the zoom level. ([#14](https://github.com/davep/complexitty/issues/14)) +- Added `CopyCommandLineToClipboard`. ## v0.2.0 diff --git a/src/complexitty/commands/__init__.py b/src/complexitty/commands/__init__.py index cf4d075..ae3f5b4 100644 --- a/src/complexitty/commands/__init__.py +++ b/src/complexitty/commands/__init__.py @@ -11,7 +11,7 @@ SetColourToShadesOfGreen, SetColourToShadesOfRed, ) -from .main import Quit +from .main import CopyCommandLineToClipboard, Quit from .navigation import ( GoMiddle, GoTo, @@ -42,6 +42,7 @@ ############################################################################## # Exports. __all__ = [ + "CopyCommandLineToClipboard", "DecreaseMaximumIteration", "DecreaseMultibrot", "GreatlyDecreaseMaximumIteration", diff --git a/src/complexitty/commands/main.py b/src/complexitty/commands/main.py index 56d515c..a022354 100644 --- a/src/complexitty/commands/main.py +++ b/src/complexitty/commands/main.py @@ -14,4 +14,11 @@ class Quit(Command): SHOW_IN_FOOTER = True +############################################################################## +class CopyCommandLineToClipboard(Command): + """Copy the command line for the current view to the clipboard""" + + BINDING_KEY = "c" + + ### main.py ends here diff --git a/src/complexitty/providers/main.py b/src/complexitty/providers/main.py index 519f38c..2153a86 100644 --- a/src/complexitty/providers/main.py +++ b/src/complexitty/providers/main.py @@ -12,6 +12,7 @@ ############################################################################## # Local imports. from ..commands import ( + CopyCommandLineToClipboard, DecreaseMaximumIteration, DecreaseMultibrot, GoMiddle, @@ -55,6 +56,7 @@ def commands(self) -> CommandHits: Yields: The commands for the command palette. """ + yield CopyCommandLineToClipboard() yield ChangeTheme() yield DecreaseMaximumIteration() yield DecreaseMultibrot() diff --git a/src/complexitty/screens/main.py b/src/complexitty/screens/main.py index 7f576c1..cbaab4f 100644 --- a/src/complexitty/screens/main.py +++ b/src/complexitty/screens/main.py @@ -22,6 +22,7 @@ ############################################################################## # Local imports. from ..commands import ( + CopyCommandLineToClipboard, DecreaseMaximumIteration, DecreaseMultibrot, GoMiddle, @@ -75,6 +76,7 @@ class Main(EnhancedScreen[None]): ChangeTheme, Quit, # Everything else. + CopyCommandLineToClipboard, DecreaseMaximumIteration, DecreaseMultibrot, GoMiddle, @@ -253,5 +255,20 @@ async def action_go_to_command(self) -> None: severity="error", ) + def action_copy_command_line_to_clipboard_command(self) -> None: + """Copy the current view as a command, to the clipboard.""" + plot = self.query_one(Mandelbrot) + command = ( + f"complexitty " + f"--x-position={plot.x_position} " + f"--y-position={plot.y_position} " + f"--zoom={plot.zoom} " + f"--max-iteration={plot.max_iteration} " + f"--multibrot={plot.multibrot} " + f"--colour-map={plot.colour_map.__name__}" + ) + self.app.copy_to_clipboard(command) + self.notify(command, title="Copied") + ### main.py ends here From b6c70609bc74b8dd409876f231e9f399e58ef94d Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 23 Apr 2025 16:33:59 +0100 Subject: [PATCH 2/2] :books: Link the ChangeLog to the PR --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 72b83f2..9108e63 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,6 +11,7 @@ - Changed the display of the X/Y location so that the precision adapts to the zoom level. ([#14](https://github.com/davep/complexitty/issues/14)) - Added `CopyCommandLineToClipboard`. + ([#20](https://github.com/davep/complexitty/pull/20)) ## v0.2.0