@@ -34,6 +34,10 @@ fn main() -> Result<()> {
34
34
std:: process:: exit ( 1 ) ;
35
35
}
36
36
37
+ // Disable clipboard when outputting to stdout (unless clipboard is explicitly enabled)
38
+ let no_clipboard = args. no_clipboard ||
39
+ args. output_file . as_ref ( ) . map_or ( false , |f| f == "-" ) ;
40
+
37
41
// ~~~ Clipboard Daemon ~~~
38
42
#[ cfg( target_os = "linux" ) ]
39
43
{
@@ -122,51 +126,73 @@ fn main() -> Result<()> {
122
126
123
127
// ~~~ Code2Prompt ~~~
124
128
let mut session = Code2PromptSession :: new ( configuration. build ( ) ?) ;
125
- let spinner = setup_spinner ( "Traversing directory and building tree..." ) ;
129
+ let spinner = if !args. quiet {
130
+ Some ( setup_spinner ( "Traversing directory and building tree..." ) )
131
+ } else {
132
+ None
133
+ } ;
126
134
127
135
// ~~~ Gather Repository Data ~~~
128
136
// Load Codebase
129
137
session. load_codebase ( ) . unwrap_or_else ( |e| {
130
- spinner. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
138
+ if let Some ( ref s) = spinner {
139
+ s. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
140
+ }
131
141
error ! ( "Failed to build directory tree: {}" , e) ;
132
142
std:: process:: exit ( 1 ) ;
133
143
} ) ;
134
- spinner. finish_with_message ( "Done!" . green ( ) . to_string ( ) ) ;
144
+ if let Some ( ref s) = spinner {
145
+ s. finish_with_message ( "Done!" . green ( ) . to_string ( ) ) ;
146
+ }
135
147
136
148
// ~~~ Git Related ~~~
137
149
// Git Diff
138
150
if session. config . diff_enabled {
139
- spinner. set_message ( "Generating git diff..." ) ;
151
+ if let Some ( ref s) = spinner {
152
+ s. set_message ( "Generating git diff..." ) ;
153
+ }
140
154
session. load_git_diff ( ) . unwrap_or_else ( |e| {
141
- spinner. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
155
+ if let Some ( ref s) = spinner {
156
+ s. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
157
+ }
142
158
error ! ( "Failed to generate git diff: {}" , e) ;
143
159
std:: process:: exit ( 1 ) ;
144
160
} ) ;
145
161
}
146
162
147
163
// Load Git diff between branches if provided
148
164
if session. config . diff_branches . is_some ( ) {
149
- spinner. set_message ( "Generating git diff between two branches..." ) ;
165
+ if let Some ( ref s) = spinner {
166
+ s. set_message ( "Generating git diff between two branches..." ) ;
167
+ }
150
168
session
151
169
. load_git_diff_between_branches ( )
152
170
. unwrap_or_else ( |e| {
153
- spinner. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
171
+ if let Some ( ref s) = spinner {
172
+ s. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
173
+ }
154
174
error ! ( "Failed to generate git diff: {}" , e) ;
155
175
std:: process:: exit ( 1 ) ;
156
176
} ) ;
157
177
}
158
178
159
179
// Load Git log between branches if provided
160
180
if session. config . log_branches . is_some ( ) {
161
- spinner. set_message ( "Generating git log between two branches..." ) ;
181
+ if let Some ( ref s) = spinner {
182
+ s. set_message ( "Generating git log between two branches..." ) ;
183
+ }
162
184
session. load_git_log_between_branches ( ) . unwrap_or_else ( |e| {
163
- spinner. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
185
+ if let Some ( ref s) = spinner {
186
+ s. finish_with_message ( "Failed!" . red ( ) . to_string ( ) ) ;
187
+ }
164
188
error ! ( "Failed to generate git log: {}" , e) ;
165
189
std:: process:: exit ( 1 ) ;
166
190
} ) ;
167
191
}
168
192
169
- spinner. finish_with_message ( "Done!" . green ( ) . to_string ( ) ) ;
193
+ if let Some ( ref s) = spinner {
194
+ s. finish_with_message ( "Done!" . green ( ) . to_string ( ) ) ;
195
+ }
170
196
171
197
// ~~~ Template ~~~
172
198
@@ -192,14 +218,16 @@ fn main() -> Result<()> {
192
218
} ;
193
219
let model_info = rendered. model_info ;
194
220
195
- println ! (
196
- "{}{}{} Token count: {}, Model info: {}" ,
197
- "[" . bold( ) . white( ) ,
198
- "i" . bold( ) . blue( ) ,
199
- "]" . bold( ) . white( ) ,
200
- formatted_token_count,
201
- model_info
202
- ) ;
221
+ if !args. quiet {
222
+ println ! (
223
+ "{}{}{} Token count: {}, Model info: {}" ,
224
+ "[" . bold( ) . white( ) ,
225
+ "i" . bold( ) . blue( ) ,
226
+ "]" . bold( ) . white( ) ,
227
+ formatted_token_count,
228
+ model_info
229
+ ) ;
230
+ }
203
231
204
232
// ~~~ Token Map Display ~~~
205
233
if args. token_map {
@@ -241,7 +269,7 @@ fn main() -> Result<()> {
241
269
}
242
270
243
271
// ~~~ Copy to Clipboard ~~~
244
- if !args . no_clipboard {
272
+ if !no_clipboard {
245
273
#[ cfg( target_os = "linux" ) ]
246
274
{
247
275
use clipboard:: spawn_clipboard_daemon;
@@ -252,22 +280,27 @@ fn main() -> Result<()> {
252
280
use crate :: clipboard:: copy_text_to_clipboard;
253
281
match copy_text_to_clipboard ( & rendered. prompt ) {
254
282
Ok ( _) => {
255
- println ! (
256
- "{}{}{} {}" ,
257
- "[" . bold( ) . white( ) ,
258
- "✓" . bold( ) . green( ) ,
259
- "]" . bold( ) . white( ) ,
260
- "Copied to clipboard successfully." . green( )
261
- ) ;
283
+ if !args. quiet {
284
+ println ! (
285
+ "{}{}{} {}" ,
286
+ "[" . bold( ) . white( ) ,
287
+ "✓" . bold( ) . green( ) ,
288
+ "]" . bold( ) . white( ) ,
289
+ "Copied to clipboard successfully." . green( )
290
+ ) ;
291
+ }
262
292
}
263
293
Err ( e) => {
264
- eprintln ! (
265
- "{}{}{} {}" ,
266
- "[" . bold( ) . white( ) ,
267
- "!" . bold( ) . red( ) ,
268
- "]" . bold( ) . white( ) ,
269
- format!( "Failed to copy to clipboard: {}" , e) . red( )
270
- ) ;
294
+ if !args. quiet {
295
+ eprintln ! (
296
+ "{}{}{} {}" ,
297
+ "[" . bold( ) . white( ) ,
298
+ "!" . bold( ) . red( ) ,
299
+ "]" . bold( ) . white( ) ,
300
+ format!( "Failed to copy to clipboard: {}" , e) . red( )
301
+ ) ;
302
+ }
303
+ // Always print the prompt if clipboard fails, regardless of quiet mode
271
304
println ! ( "{}" , & rendered. prompt) ;
272
305
}
273
306
}
@@ -276,7 +309,7 @@ fn main() -> Result<()> {
276
309
277
310
// ~~~ Output File ~~~
278
311
if let Some ( output_path) = & args. output_file {
279
- write_to_file ( output_path, & rendered. prompt ) ?;
312
+ write_to_file ( output_path, & rendered. prompt , args . quiet ) ?;
280
313
}
281
314
282
315
Ok ( ( ) )
0 commit comments