diff --git a/ChangeLog.md b/ChangeLog.md index 4dc6af6..9108e63 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,6 +10,8 @@ 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`. + ([#20](https://github.com/davep/complexitty/pull/20)) ## 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