Skip to content

Commit 9c571bd

Browse files
authored
chore: use centralized colors (#3113)
* use theme color * missing constants.rs
1 parent 71ba5f1 commit 9c571bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1678
-1160
lines changed

crates/chat-cli/src/api_client/delay_interceptor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use aws_smithy_types::config_bag::{
1313
Storable,
1414
StoreReplace,
1515
};
16-
use crossterm::style::Color;
1716
use crossterm::{
1817
execute,
1918
style,
2019
};
2120

2221
use crate::api_client::MAX_RETRY_DELAY_DURATION;
22+
use crate::theme::StyledText;
2323

2424
#[derive(Debug, Clone)]
2525
pub struct DelayTrackingInterceptor {
@@ -39,9 +39,9 @@ impl DelayTrackingInterceptor {
3939
let mut stderr = std::io::stderr();
4040
let _ = execute!(
4141
stderr,
42-
style::SetForegroundColor(Color::Yellow),
42+
StyledText::warning_fg(),
4343
style::Print("\nWARNING: "),
44-
style::SetForegroundColor(Color::Reset),
44+
StyledText::reset(),
4545
style::Print(message),
4646
style::Print("\n")
4747
);

crates/chat-cli/src/cli/agent/legacy/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use super::{
1818
use crate::cli::agent::hook::Hook;
1919
use crate::cli::agent::legacy::context::LegacyContextConfig;
2020
use crate::os::Os;
21+
use crate::theme::StyledText;
2122
use crate::util::directories;
2223

2324
/// Performs the migration from legacy profile configuration to agent configuration if it hasn't
@@ -110,10 +111,7 @@ pub async fn migrate(os: &mut Os, force: bool) -> eyre::Result<Option<Vec<Agent>
110111
.interact_on_opt(&dialoguer::console::Term::stdout())
111112
{
112113
Ok(sel) => {
113-
let _ = crossterm::execute!(
114-
std::io::stdout(),
115-
crossterm::style::SetForegroundColor(crossterm::style::Color::Magenta)
116-
);
114+
let _ = crossterm::execute!(std::io::stdout(), StyledText::emphasis_fg());
117115
sel
118116
},
119117
// Ctrl‑C -> Err(Interrupted)

crates/chat-cli/src/cli/agent/mod.rs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use std::path::{
1919
PathBuf,
2020
};
2121

22-
use crossterm::style::{
23-
Color,
24-
Stylize as _,
25-
};
22+
use crossterm::style::Stylize as _;
2623
use crossterm::{
2724
execute,
2825
queue,
@@ -65,6 +62,7 @@ use crate::cli::agent::hook::{
6562
};
6663
use crate::database::settings::Setting;
6764
use crate::os::Os;
65+
use crate::theme::StyledText;
6866
use crate::util::{
6967
self,
7068
MCP_SERVER_TOOL_DELIMITER,
@@ -232,13 +230,13 @@ impl Agent {
232230
if mcp_servers.mcp_servers.contains_key(name) {
233231
let _ = queue!(
234232
output,
235-
style::SetForegroundColor(Color::Yellow),
233+
StyledText::warning_fg(),
236234
style::Print("WARNING: "),
237-
style::ResetColor,
235+
StyledText::reset(),
238236
style::Print("MCP server '"),
239-
style::SetForegroundColor(Color::Green),
237+
StyledText::success_fg(),
240238
style::Print(name),
241-
style::ResetColor,
239+
StyledText::reset(),
242240
style::Print(
243241
"' is already configured in agent config. Skipping duplicate from legacy mcp.json.\n"
244242
)
@@ -455,10 +453,10 @@ impl Agents {
455453
if !mcp_enabled {
456454
let _ = execute!(
457455
output,
458-
style::SetForegroundColor(Color::Yellow),
456+
StyledText::warning_fg(),
459457
style::Print("\n"),
460458
style::Print("⚠️ WARNING: "),
461-
style::SetForegroundColor(Color::Reset),
459+
StyledText::reset(),
462460
style::Print("MCP functionality has been disabled by your administrator.\n\n"),
463461
);
464462
}
@@ -517,9 +515,9 @@ impl Agents {
517515
load_metadata.load_failed_count += 1;
518516
let _ = queue!(
519517
output,
520-
style::SetForegroundColor(Color::Red),
518+
StyledText::error_fg(),
521519
style::Print("Error: "),
522-
style::ResetColor,
520+
StyledText::reset(),
523521
style::Print(e),
524522
style::Print("\n"),
525523
);
@@ -555,9 +553,9 @@ impl Agents {
555553
load_metadata.load_failed_count += 1;
556554
let _ = queue!(
557555
output,
558-
style::SetForegroundColor(Color::Red),
556+
StyledText::error_fg(),
559557
style::Print("Error: "),
560-
style::ResetColor,
558+
StyledText::reset(),
561559
style::Print(e),
562560
style::Print("\n"),
563561
);
@@ -625,13 +623,13 @@ impl Agents {
625623
if local_names.contains(name) {
626624
let _ = queue!(
627625
output,
628-
style::SetForegroundColor(style::Color::Yellow),
626+
StyledText::warning_fg(),
629627
style::Print("WARNING: "),
630-
style::ResetColor,
628+
StyledText::reset(),
631629
style::Print("Agent conflict for "),
632-
style::SetForegroundColor(style::Color::Green),
630+
StyledText::success_fg(),
633631
style::Print(name),
634-
style::ResetColor,
632+
StyledText::reset(),
635633
style::Print(". Using workspace version.\n")
636634
);
637635
false
@@ -655,15 +653,15 @@ impl Agents {
655653
}
656654
let _ = queue!(
657655
output,
658-
style::SetForegroundColor(Color::Red),
656+
StyledText::error_fg(),
659657
style::Print("Error"),
660-
style::SetForegroundColor(Color::Yellow),
658+
StyledText::warning_fg(),
661659
style::Print(format!(
662660
": no agent with name {} found. Falling back to user specified default",
663661
name
664662
)),
665663
style::Print("\n"),
666-
style::SetForegroundColor(Color::Reset)
664+
StyledText::reset(),
667665
);
668666
}
669667

@@ -673,15 +671,15 @@ impl Agents {
673671
}
674672
let _ = queue!(
675673
output,
676-
style::SetForegroundColor(Color::Red),
674+
StyledText::error_fg(),
677675
style::Print("Error"),
678-
style::SetForegroundColor(Color::Yellow),
676+
StyledText::warning_fg(),
679677
style::Print(format!(
680678
": user defined default {} not found. Falling back to in-memory default",
681679
user_set_default
682680
)),
683681
style::Print("\n"),
684-
style::SetForegroundColor(Color::Reset)
682+
StyledText::reset(),
685683
);
686684
}
687685

@@ -739,17 +737,17 @@ impl Agents {
739737
let name = &agent.name;
740738
let _ = execute!(
741739
output,
742-
style::SetForegroundColor(Color::Yellow),
740+
StyledText::warning_fg(),
743741
style::Print("WARNING "),
744-
style::ResetColor,
742+
StyledText::reset(),
745743
style::Print("Agent config "),
746-
style::SetForegroundColor(Color::Green),
744+
StyledText::success_fg(),
747745
style::Print(name),
748-
style::ResetColor,
746+
StyledText::reset(),
749747
style::Print(" is malformed at "),
750-
style::SetForegroundColor(Color::Yellow),
748+
StyledText::warning_fg(),
751749
style::Print(&e.instance_path),
752-
style::ResetColor,
750+
StyledText::reset(),
753751
style::Print(format!(": {e}\n")),
754752
);
755753
}
@@ -892,17 +890,17 @@ pub fn queue_permission_override_warning(
892890
) -> Result<(), std::io::Error> {
893891
Ok(queue!(
894892
output,
895-
style::SetForegroundColor(Color::Yellow),
893+
StyledText::warning_fg(),
896894
style::Print("WARNING: "),
897-
style::ResetColor,
895+
StyledText::reset(),
898896
style::Print("You have trusted "),
899-
style::SetForegroundColor(Color::Green),
897+
StyledText::success_fg(),
900898
style::Print(tool_name),
901-
style::ResetColor,
899+
StyledText::reset(),
902900
style::Print(" tool, which overrides the toolsSettings: "),
903-
style::SetForegroundColor(Color::Cyan),
901+
StyledText::brand_fg(),
904902
style::Print(overridden_settings),
905-
style::ResetColor,
903+
StyledText::reset(),
906904
style::Print("\n"),
907905
)?)
908906
}

crates/chat-cli/src/cli/agent/root_command_args.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use clap::{
66
Args,
77
Subcommand,
88
};
9-
use crossterm::style::Color;
109
use crossterm::{
1110
queue,
1211
style,
@@ -25,6 +24,7 @@ use super::{
2524
};
2625
use crate::database::settings::Setting;
2726
use crate::os::Os;
27+
use crate::theme::StyledText;
2828
use crate::util::directories;
2929

3030
#[derive(Clone, Debug, Subcommand, PartialEq, Eq)]
@@ -175,9 +175,9 @@ impl AgentArgs {
175175
let Ok(instance) = serde_json::to_value(&agent) else {
176176
queue!(
177177
stderr,
178-
style::SetForegroundColor(style::Color::Red),
178+
StyledText::error_fg(),
179179
style::Print("Error: "),
180-
style::ResetColor,
180+
StyledText::reset(),
181181
style::Print("failed to obtain value from agent provided. Aborting validation"),
182182
)?;
183183
break 'validate;
@@ -188,9 +188,9 @@ impl AgentArgs {
188188
Err(e) => {
189189
queue!(
190190
stderr,
191-
style::SetForegroundColor(style::Color::Red),
191+
StyledText::error_fg(),
192192
style::Print("Error: "),
193-
style::ResetColor,
193+
StyledText::reset(),
194194
style::Print(format!("failed to obtain schema: {e}. Aborting validation"))
195195
)?;
196196
break 'validate;
@@ -201,27 +201,27 @@ impl AgentArgs {
201201
let name = &agent.name;
202202
queue!(
203203
stderr,
204-
style::SetForegroundColor(Color::Yellow),
204+
StyledText::warning_fg(),
205205
style::Print("WARNING "),
206-
style::ResetColor,
206+
StyledText::reset(),
207207
style::Print("Agent config "),
208-
style::SetForegroundColor(Color::Green),
208+
StyledText::success_fg(),
209209
style::Print(name),
210-
style::ResetColor,
210+
StyledText::reset(),
211211
style::Print(" is malformed at "),
212-
style::SetForegroundColor(Color::Yellow),
212+
StyledText::warning_fg(),
213213
style::Print(&e.instance_path),
214-
style::ResetColor,
214+
StyledText::reset(),
215215
style::Print(format!(": {e}\n")),
216216
)?;
217217
}
218218
},
219219
Err(e) => {
220220
let _ = queue!(
221221
stderr,
222-
style::SetForegroundColor(Color::Red),
222+
StyledText::error_fg(),
223223
style::Print("Error: "),
224-
style::ResetColor,
224+
StyledText::reset(),
225225
style::Print(e),
226226
style::Print("\n"),
227227
);
@@ -235,15 +235,15 @@ impl AgentArgs {
235235
if !force {
236236
let _ = queue!(
237237
stderr,
238-
style::SetForegroundColor(Color::Yellow),
238+
StyledText::warning_fg(),
239239
style::Print("WARNING: "),
240-
style::ResetColor,
240+
StyledText::reset(),
241241
style::Print(
242242
"manual migrate is potentially destructive to existing agent configs with name collision. Use"
243243
),
244-
style::SetForegroundColor(Color::Cyan),
244+
StyledText::brand_fg(),
245245
style::Print(" --force "),
246-
style::ResetColor,
246+
StyledText::reset(),
247247
style::Print("to run"),
248248
style::Print("\n"),
249249
);
@@ -255,9 +255,9 @@ impl AgentArgs {
255255
let migrated_count = new_agents.len();
256256
let _ = queue!(
257257
stderr,
258-
style::SetForegroundColor(Color::Green),
258+
StyledText::success_fg(),
259259
style::Print("✓ Success: "),
260-
style::ResetColor,
260+
StyledText::reset(),
261261
style::Print(format!(
262262
"Profile migration successful. Migrated {} agent(s)\n",
263263
migrated_count
@@ -267,18 +267,18 @@ impl AgentArgs {
267267
Ok(None) => {
268268
let _ = queue!(
269269
stderr,
270-
style::SetForegroundColor(Color::Blue),
270+
StyledText::info_fg(),
271271
style::Print("Info: "),
272-
style::ResetColor,
272+
StyledText::reset(),
273273
style::Print("Migration was not performed. Nothing to migrate\n"),
274274
);
275275
},
276276
Err(e) => {
277277
let _ = queue!(
278278
stderr,
279-
style::SetForegroundColor(Color::Red),
279+
StyledText::error_fg(),
280280
style::Print("Error: "),
281-
style::ResetColor,
281+
StyledText::reset(),
282282
style::Print(format!("Migration did not happen for the following reason: {e}\n")),
283283
);
284284
},
@@ -295,19 +295,19 @@ impl AgentArgs {
295295

296296
let _ = queue!(
297297
stderr,
298-
style::SetForegroundColor(Color::Green),
298+
StyledText::success_fg(),
299299
style::Print("✓ Default agent set to '"),
300300
style::Print(&agent.name),
301301
style::Print("'. This will take effect the next time q chat is launched.\n"),
302-
style::ResetColor,
302+
StyledText::reset(),
303303
);
304304
},
305305
Err(e) => {
306306
let _ = queue!(
307307
stderr,
308-
style::SetForegroundColor(Color::Red),
308+
StyledText::error_fg(),
309309
style::Print("Error: "),
310-
style::ResetColor,
310+
StyledText::reset(),
311311
style::Print(format!("Failed to set default agent: {e}\n")),
312312
);
313313
},

0 commit comments

Comments
 (0)