mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
feat: Add /add-clipboard-image command
This commit is contained in:
parent
15f589f642
commit
73bf90f007
1 changed files with 24 additions and 0 deletions
|
@ -2,10 +2,12 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
from PIL import ImageGrab
|
||||||
|
|
||||||
from aider import models, prompts, voice
|
from aider import models, prompts, voice
|
||||||
from aider.help import Help, install_help_extra
|
from aider.help import Help, install_help_extra
|
||||||
|
@ -880,6 +882,28 @@ class Commands:
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def cmd_add_clipboard_image(self, args):
|
||||||
|
"Add an image from the clipboard to the chat"
|
||||||
|
try:
|
||||||
|
image = ImageGrab.grabclipboard()
|
||||||
|
if image is None:
|
||||||
|
self.io.tool_error("No image found in clipboard.")
|
||||||
|
return
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
||||||
|
image.save(temp_file.name, "PNG")
|
||||||
|
temp_file_path = temp_file.name
|
||||||
|
|
||||||
|
abs_file_path = Path(temp_file_path).resolve()
|
||||||
|
self.coder.abs_fnames.add(str(abs_file_path))
|
||||||
|
self.io.tool_output(f"Added clipboard image to the chat: {abs_file_path}")
|
||||||
|
self.coder.check_added_files()
|
||||||
|
|
||||||
|
return prompts.added_files.format(fnames=str(abs_file_path))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.io.tool_error(f"Error adding clipboard image: {e}")
|
||||||
|
|
||||||
|
|
||||||
def expand_subdir(file_path):
|
def expand_subdir(file_path):
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue