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