@@ -53,6 +53,11 @@ use regex::Regex;
5353pub use region_check:: region_check;
5454use tracing:: warn;
5555
56+ // ANSI color codes
57+ const PURPLE : u8 = 93 ;
58+ const GRAY : u8 = 8 ;
59+ const MAGENTA : u8 = 13 ;
60+
5661/// Glob patterns against full paths
5762pub fn glob_dir ( glob : & GlobSet , directory : impl AsRef < Path > ) -> Result < Vec < PathBuf > > {
5863 let mut files = Vec :: new ( ) ;
@@ -276,6 +281,71 @@ pub fn choose(prompt: impl Display, options: &[impl ToString]) -> Result<Option<
276281 }
277282}
278283
284+ pub fn welcome_login_prompt ( ) -> Result < bool > {
285+ use crossterm:: event:: {
286+ self ,
287+ Event ,
288+ KeyCode ,
289+ KeyEvent ,
290+ } ;
291+ use crossterm:: style:: {
292+ Color ,
293+ ResetColor ,
294+ SetForegroundColor ,
295+ } ;
296+ use crossterm:: terminal:: {
297+ disable_raw_mode,
298+ enable_raw_mode,
299+ } ;
300+
301+ if !stdout ( ) . is_terminal ( ) {
302+ warn ! ( "called welcome_login_prompt while stdout is not a terminal" ) ;
303+ return Ok ( true ) ;
304+ }
305+
306+ println ! ( ) ;
307+ print ! ( "Welcome to " ) ;
308+ print ! (
309+ "{}{}{}" ,
310+ SetForegroundColor ( Color :: AnsiValue ( PURPLE ) ) ,
311+ PRODUCT_NAME ,
312+ ResetColor
313+ ) ;
314+ println ! ( ", let's get you signed in!" ) ;
315+ println ! ( ) ;
316+
317+ // Print instruction line with styling
318+ print ! ( "{}Press " , SetForegroundColor ( Color :: AnsiValue ( GRAY ) ) ) ;
319+ print ! (
320+ "{}enter{}" ,
321+ SetForegroundColor ( Color :: AnsiValue ( MAGENTA ) ) ,
322+ SetForegroundColor ( Color :: AnsiValue ( GRAY ) )
323+ ) ;
324+ print ! ( " to continue to the browser or " ) ;
325+ print ! (
326+ "{}esc{}" ,
327+ SetForegroundColor ( Color :: AnsiValue ( MAGENTA ) ) ,
328+ SetForegroundColor ( Color :: AnsiValue ( GRAY ) )
329+ ) ;
330+ println ! ( " to cancel{}" , ResetColor ) ;
331+ println ! ( ) ;
332+
333+ enable_raw_mode ( ) ?;
334+ let result = loop {
335+ if let Ok ( Event :: Key ( KeyEvent { code, .. } ) ) = event:: read ( ) {
336+ match code {
337+ KeyCode :: Enter => break Ok ( true ) ,
338+ KeyCode :: Esc => break Ok ( false ) ,
339+ KeyCode :: Char ( 'c' ) if event:: read ( ) . is_ok ( ) => break Ok ( false ) , // Ctrl+C
340+ _ => { } ,
341+ }
342+ }
343+ } ;
344+ disable_raw_mode ( ) ?;
345+
346+ result
347+ }
348+
279349pub fn input ( prompt : & str , initial_text : Option < & str > ) -> Result < String > {
280350 if !stdout ( ) . is_terminal ( ) {
281351 warn ! ( "called input while stdout is not a terminal" ) ;
@@ -319,6 +389,14 @@ pub fn dialoguer_theme() -> ColorfulTheme {
319389 ..ColorfulTheme :: default ( )
320390 }
321391}
392+
393+ pub fn login_spinner_message ( ) -> String {
394+ format ! (
395+ " \x1b [38;5;{}mOpening browser... | Press \x1b [38;5;{}m(^) + C\x1b [38;5;{}m to cancel\x1b [0m" ,
396+ GRAY , MAGENTA , GRAY
397+ )
398+ }
399+
322400pub async fn is_logged_in_check ( ) -> bool {
323401 std:: env:: var ( "AMAZON_Q_SIGV4" ) . is_ok_and ( |v| !v. is_empty ( ) ) || fig_auth:: is_logged_in ( ) . await
324402}
0 commit comments