Skip to content

Commit

Permalink
color coding
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorpela committed Oct 8, 2024
1 parent 9da0255 commit d2fb20e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion kopipasta/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
from typing import Dict, List, Optional, Set, Tuple
import pyperclip
import fnmatch
from pygments import highlight
from pygments.lexers import get_lexer_for_filename, TextLexer
from pygments.formatters import TerminalFormatter
import pygments.util

import requests

FileTuple = Tuple[str, bool, Optional[List[str]], str]

def get_colored_code(file_path, code):
try:
lexer = get_lexer_for_filename(file_path)
except pygments.util.ClassNotFound:
lexer = TextLexer()
return highlight(code, lexer, TerminalFormatter())

def read_gitignore():
default_ignore_patterns = [
'.git', 'node_modules', 'venv', '.venv', 'dist', '.idea', '__pycache__',
Expand Down Expand Up @@ -375,7 +386,8 @@ def select_file_patches(file_path):
print(f"\nSelecting patches for {file_path}")
for index, (chunk_code, start_line, end_line) in enumerate(code_chunks):
print(f"\nChunk {index + 1} (Lines {start_line + 1}-{end_line}):")
print(f"```{language}\n{chunk_code}\n```")
colored_chunk = get_colored_code(file_path, chunk_code)
print(colored_chunk)
while True:
choice = input("(y)es include / (n)o skip / (q)uit rest of file? ").lower()
if choice == 'y':
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyperclip==1.9.0
requests==2.32.3
Pygments==2.18.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="kopipasta",
version="0.17.0",
version="0.18.0",
author="Mikko Korpela",
author_email="[email protected]",
description="A CLI tool to generate prompts with project structure and file contents",
Expand Down

0 comments on commit d2fb20e

Please sign in to comment.