File tree Expand file tree Collapse file tree 3 files changed +133
-94
lines changed Expand file tree Collapse file tree 3 files changed +133
-94
lines changed Original file line number Diff line number Diff line change @@ -433,8 +433,8 @@ def main(
433
433
error_console .print (
434
434
f"Output { 'appended' if append else 'written' } to [green]{ outfile } [/]"
435
435
)
436
- # Handle clipboard only if not writing to file
437
- else :
436
+ # Only use clipboard if not writing to file AND not just printing to stdout
437
+ elif not print_output or append :
438
438
if append :
439
439
try :
440
440
existing_clipboard = pyperclip .paste ()
@@ -444,13 +444,24 @@ def main(
444
444
"[yellow]Warning: Could not read clipboard for append[/]"
445
445
)
446
446
447
- pyperclip .copy (result )
448
- # Calculate total lines outside the f-string
449
- total_lines = sum (f .content .count ("\n " ) + 1 for f in format_result .files )
450
- error_console .print (
451
- f"{ 'Appended' if append else 'Copied' } to clipboard "
452
- f"(~{ format_result .total_tokens :,} tokens, { total_lines :,} lines)"
453
- )
447
+ try :
448
+ pyperclip .copy (result )
449
+ # Calculate total lines outside the f-string
450
+ total_lines = sum (
451
+ f .content .count ("\n " ) + 1 for f in format_result .files
452
+ )
453
+ error_console .print (
454
+ f"{ 'Appended' if append else 'Copied' } to clipboard "
455
+ f"(~{ format_result .total_tokens :,} tokens, { total_lines :,} lines)"
456
+ )
457
+ except Exception as e :
458
+ error_console .print (
459
+ f"[yellow]Warning: Could not copy to clipboard: { str (e )} [/]"
460
+ )
461
+ if not print_output :
462
+ # If clipboard failed and we're not printing, show the content
463
+ error_console .print ("[cyan]Content would have been:[/]" )
464
+ print (result )
454
465
455
466
# Print to stdout only if explicitly requested
456
467
if print_output :
Original file line number Diff line number Diff line change 4
4
import re
5
5
from pathlib import Path
6
6
7
- runner = CliRunner (mix_stderr = False )
7
+ runner = CliRunner ()
8
8
9
9
10
10
def strip_ansi (text : str ) -> str :
@@ -259,7 +259,7 @@ def mock_copy(text):
259
259
260
260
def test_cli_github_item_basic (monkeypatch ):
261
261
"""Basic test for GitHub item handling that doesn't rely on internal implementation."""
262
- runner = CliRunner (mix_stderr = False )
262
+ runner = CliRunner ()
263
263
264
264
# Instead of mocking complex internals, just provide a simple mock for the scan_directory function
265
265
# so it returns a known result when the CLI processes a GitHub item
You can’t perform that action at this time.
0 commit comments