Skip to content

Commit 819699e

Browse files
feat(cli): add --raw flag to skip syntax highlighting in search output
Add option to display search results without syntax highlighting for simpler output or when highlighting is not needed. Co-authored-by: Bob <[email protected]>
1 parent ecd8c03 commit 819699e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

gptme_rag/cli.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ def index(directory: Path, pattern: str, persist_dir: Path):
7373
)
7474
@click.option("--max-tokens", default=4000, help="Maximum tokens in context window")
7575
@click.option("--show-context", is_flag=True, help="Show the full context content")
76+
@click.option("--raw", is_flag=True, help="Skip syntax highlighting")
7677
def search(
7778
query: str,
7879
paths: list[Path],
7980
n_results: int,
8081
persist_dir: Path,
8182
max_tokens: int,
8283
show_context: bool,
84+
raw: bool,
8385
):
8486
"""Search the index and assemble context."""
8587
paths = [path.resolve() for path in paths]
@@ -107,13 +109,17 @@ def search(
107109
for doc in context.documents:
108110
# Display file with syntax highlighting
109111
lexer = doc.metadata.get("extension", "").lstrip(".") or "text"
110-
syntax = Syntax(
111-
doc.format_xml(),
112-
lexer,
113-
theme="monokai",
114-
word_wrap=True,
112+
output = doc.format_xml()
113+
console.print(
114+
output
115+
if raw
116+
else Syntax(
117+
output,
118+
lexer,
119+
theme="monokai",
120+
word_wrap=True,
121+
)
115122
)
116-
console.print(syntax)
117123
console.print()
118124
return
119125

0 commit comments

Comments
 (0)