11use std:: io:: Write ;
22use std:: time:: Duration ;
33
4+ use fig_util:: system_info:: in_cloudshell;
5+
46use super :: ChatError ;
57
8+ const GOV_REGIONS : & [ & str ] = & [ "us-gov-east-1" , "us-gov-west-1" ] ;
9+
10+ pub fn region_check ( capability : & ' static str ) -> eyre:: Result < ( ) > {
11+ let Ok ( region) = std:: env:: var ( "AWS_REGION" ) else {
12+ return Ok ( ( ) ) ;
13+ } ;
14+
15+ if in_cloudshell ( ) && GOV_REGIONS . contains ( & region. as_str ( ) ) {
16+ eyre:: bail!( "AWS GovCloud ({region}) is not supported for {capability}." ) ;
17+ }
18+
19+ Ok ( ( ) )
20+ }
21+
622pub fn truncate_safe ( s : & str , max_bytes : usize ) -> & str {
723 if s. len ( ) <= max_bytes {
824 return s;
@@ -29,6 +45,57 @@ pub fn animate_output(output: &mut impl Write, bytes: &[u8]) -> Result<(), ChatE
2945 Ok ( ( ) )
3046}
3147
48+ /// Play the terminal bell notification sound
49+ pub fn play_notification_bell ( requires_confirmation : bool ) {
50+ // Don't play bell for tools that don't require confirmation
51+ if !requires_confirmation {
52+ return ;
53+ }
54+
55+ // Check if we should play the bell based on terminal type
56+ if should_play_bell ( ) {
57+ print ! ( "\x07 " ) ; // ASCII bell character
58+ std:: io:: stdout ( ) . flush ( ) . unwrap ( ) ;
59+ }
60+ }
61+
62+ /// Determine if we should play the bell based on terminal type
63+ fn should_play_bell ( ) -> bool {
64+ // Get the TERM environment variable
65+ if let Ok ( term) = std:: env:: var ( "TERM" ) {
66+ // List of terminals known to handle bell character well
67+ let bell_compatible_terms = [
68+ "xterm" ,
69+ "xterm-256color" ,
70+ "screen" ,
71+ "screen-256color" ,
72+ "tmux" ,
73+ "tmux-256color" ,
74+ "rxvt" ,
75+ "rxvt-unicode" ,
76+ "linux" ,
77+ "konsole" ,
78+ "gnome" ,
79+ "gnome-256color" ,
80+ "alacritty" ,
81+ "iterm2" ,
82+ ] ;
83+
84+ // Check if the current terminal is in the compatible list
85+ for compatible_term in bell_compatible_terms. iter ( ) {
86+ if term. starts_with ( compatible_term) {
87+ return true ;
88+ }
89+ }
90+
91+ // For other terminals, don't play the bell
92+ return false ;
93+ }
94+
95+ // If TERM is not set, default to not playing the bell
96+ false
97+ }
98+
3299#[ cfg( test) ]
33100mod tests {
34101 use super :: * ;
0 commit comments