From d5a7944d1bdf8f7e6c45e913258d0b55c5585b10 Mon Sep 17 00:00:00 2001 From: Raphael MANSUY Date: Fri, 28 Jun 2024 21:00:42 +0800 Subject: [PATCH] add copy to clipboard --- code2prompt/write_output.py | 12 ++++++++++-- poetry.lock | 12 +++++++++++- pyproject.toml | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/code2prompt/write_output.py b/code2prompt/write_output.py index 78c555c..f3e52d0 100644 --- a/code2prompt/write_output.py +++ b/code2prompt/write_output.py @@ -1,12 +1,14 @@ import click from pathlib import Path +import pyperclip def write_output(content, output_path): """ - Writes the generated content to a file or prints it to the console. + Writes the generated content to a file or prints it to the console, + and copies the content to the clipboard. Parameters: - - content (str): The content to be written or printed. + - content (str): The content to be written, printed, and copied. - output_path (str): The path to the file where the content should be written. If None, the content is printed to the console. @@ -22,3 +24,9 @@ def write_output(content, output_path): click.echo(f"Error writing to output file: {e}", err=True) else: click.echo(content) + + # Copy content to clipboard + try: + pyperclip.copy(content) + except Exception as e: + click.echo(f"Error copying to clipboard: {e}", err=True) \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index bee8291..656a369 100644 --- a/poetry.lock +++ b/poetry.lock @@ -823,6 +823,16 @@ files = [ plugins = ["importlib-metadata"] windows-terminal = ["colorama (>=0.4.6)"] +[[package]] +name = "pyperclip" +version = "1.9.0" +description = "A cross-platform clipboard module for Python. (Only handles plain text for now.)" +optional = false +python-versions = "*" +files = [ + {file = "pyperclip-1.9.0.tar.gz", hash = "sha256:b7de0142ddc81bfc5c7507eea19da920b92252b548b96186caf94a5e2527d310"}, +] + [[package]] name = "pytest" version = "8.1.1" @@ -1295,4 +1305,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = ">=3.8, <4.0" -content-hash = "d50885c4ccafa34d0b9ed749bda68104d6fc1870e143f00146be6436496ad210" +content-hash = "8e477e6e91a914b879c0eed305ae210ddb3f3d9dc9004cf648e46b981a75a601" diff --git a/pyproject.toml b/pyproject.toml index cfdf805..bd1be78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "code2prompt" -version = "0.6.0" +version = "0.6.1" description = "" authors = ["Raphael MANSUY "] readme = "README.md" @@ -12,6 +12,7 @@ click = "^8.1.7" jinja2 = "^3.1.4" prompt-toolkit = "^3.0.47" tiktoken = "^0.7.0" +pyperclip = "^1.9.0" [tool.poetry.scripts] code2prompt = "code2prompt.main:create_markdown_file"