@@ -66,16 +66,14 @@ const COMMANDS: &[&str] = &[
66
66
"/context clear --global" ,
67
67
] ;
68
68
69
- pub fn generate_prompt ( current_profile : Option < & str > ) -> String {
70
- if let Some ( profile_name) = & current_profile {
71
- if * profile_name != "default" {
72
- // Format with profile name for non-default profiles
73
- return format ! ( "[{}] > " , profile_name) ;
74
- }
75
- }
76
-
77
- // Default prompt
78
- "> " . to_string ( )
69
+ pub fn generate_prompt ( current_profile : Option < & str > , warning : bool ) -> String {
70
+ let warning_symbol = if warning { "!" . red ( ) . to_string ( ) } else { "" . to_string ( ) } ;
71
+ let profile_part = current_profile
72
+ . filter ( |& p| p != "default" )
73
+ . map ( |p| format ! ( "[{p}] " ) . cyan ( ) . to_string ( ) )
74
+ . unwrap_or_default ( ) ;
75
+
76
+ format ! ( "{profile_part}{warning_symbol}{}" , "> " . magenta( ) )
79
77
}
80
78
81
79
/// Complete commands that start with a slash
@@ -200,21 +198,6 @@ impl Validator for ChatHelper {
200
198
}
201
199
202
200
impl Highlighter for ChatHelper {
203
- fn highlight_prompt < ' b , ' s : ' b , ' p : ' b > ( & ' s self , prompt : & ' p str , _default : bool ) -> Cow < ' b , str > {
204
- // Check if the prompt contains a context profile indicator
205
- if let Some ( profile_end) = prompt. find ( "] " ) {
206
- // Split the prompt into context part and the rest
207
- let context_part = & prompt[ ..=profile_end] ;
208
- let rest = & prompt[ ( profile_end + 1 ) ..] ;
209
-
210
- // Color the context part cyan and the rest magenta
211
- Cow :: Owned ( format ! ( "{}{}" , context_part. cyan( ) , rest. magenta( ) ) )
212
- } else {
213
- // Default prompt with magenta color
214
- Cow :: Owned ( prompt. magenta ( ) . to_string ( ) )
215
- }
216
- }
217
-
218
201
fn highlight_hint < ' h > ( & self , hint : & ' h str ) -> Cow < ' h , str > {
219
202
Cow :: Owned ( format ! ( "\x1b [1m{hint}\x1b [m" ) )
220
203
}
@@ -268,13 +251,21 @@ mod tests {
268
251
#[ test]
269
252
fn test_generate_prompt ( ) {
270
253
// Test default prompt (no profile)
271
- assert_eq ! ( generate_prompt( None ) , "> " ) ;
254
+ assert_eq ! ( generate_prompt( None , false ) , "> " . magenta( ) . to_string( ) ) ;
255
+ // Test default prompt with warning
256
+ assert_eq ! ( generate_prompt( None , true ) , format!( "{}{}" , "!" . red( ) , "> " . magenta( ) ) ) ;
272
257
// Test default profile (should be same as no profile)
273
- assert_eq ! ( generate_prompt( Some ( "default" ) ) , "> " ) ;
258
+ assert_eq ! ( generate_prompt( Some ( "default" ) , false ) , "> " . magenta ( ) . to_string ( ) ) ;
274
259
// Test custom profile
275
- assert_eq ! ( generate_prompt( Some ( "test-profile" ) ) , "[test-profile] > " ) ;
276
- // Test another custom profile
277
- assert_eq ! ( generate_prompt( Some ( "dev" ) ) , "[dev] > " ) ;
260
+ assert_eq ! (
261
+ generate_prompt( Some ( "test-profile" ) , false ) ,
262
+ format!( "{}{}" , "[test-profile] " . cyan( ) , "> " . magenta( ) )
263
+ ) ;
264
+ // Test another custom profile with warning
265
+ assert_eq ! (
266
+ generate_prompt( Some ( "dev" ) , true ) ,
267
+ format!( "{}{}{}" , "[dev] " . cyan( ) , "!" . red( ) , "> " . magenta( ) )
268
+ ) ;
278
269
}
279
270
280
271
#[ test]
0 commit comments