From 22b126c2ff5540045d03f07131415db28924251b Mon Sep 17 00:00:00 2001 From: ykdy3951 Date: Sun, 11 Feb 2024 21:24:58 +0900 Subject: [PATCH] Add functionality to automatically copy command search results to Clipboard by adding pyperclip module --- cllm/main.py | 5 +++++ poetry.lock | 12 +++++++++++- pyproject.toml | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cllm/main.py b/cllm/main.py index d015ecd..6ae0c49 100644 --- a/cllm/main.py +++ b/cllm/main.py @@ -6,8 +6,10 @@ import tomllib from langchain_openai import ChatOpenAI from langchain_core.prompts import (ChatPromptTemplate, FewShotChatMessagePromptTemplate) +from rich import print as rprint from rich.progress import Progress, SpinnerColumn, TextColumn from typing import Optional +import pyperclip # version of the CLI app = typer.Typer(help="Empower your CLI experience with a command search tool driven by LLM magic!", @@ -87,6 +89,9 @@ def search(query : str): output.content = output.content[4:] typer.echo(output.content) + pyperclip.copy(output.content) + rprint("The command has been copied to [bold green]your clipboard 📋![/bold green]") + @app.callback() def main( diff --git a/poetry.lock b/poetry.lock index 43e1dc9..fdc7570 100644 --- a/poetry.lock +++ b/poetry.lock @@ -580,6 +580,16 @@ files = [ plugins = ["importlib-metadata"] windows-terminal = ["colorama (>=0.4.6)"] +[[package]] +name = "pyperclip" +version = "1.8.2" +description = "A cross-platform clipboard module for Python. (Only handles plain text for now.)" +optional = false +python-versions = "*" +files = [ + {file = "pyperclip-1.8.2.tar.gz", hash = "sha256:105254a8b04934f0bc84e9c24eb360a591aaf6535c9def5f29d92af107a9bf57"}, +] + [[package]] name = "pyyaml" version = "6.0.1" @@ -944,4 +954,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.10.9" -content-hash = "43684311cc68dbd609039326b54fa4f842805c6fd6d301554517fc6438223954" +content-hash = "71c05153842af2c9fc0bb331b6a9ac5091031910e60c5b0dd2235593d9224db0" diff --git a/pyproject.toml b/pyproject.toml index a332810..b23c92c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ python = "^3.10.9" typer = {extras = ["all"], version = "^0.9.0"} langchain-openai = "^0.0.5" langchain-core = "^0.1.22" +pyperclip = "^1.8.2" [build-system]