@@ -7,9 +7,12 @@ use std::sync::mpsc::{
7
7
TryRecvError ,
8
8
channel,
9
9
} ;
10
- use std:: thread;
11
10
use std:: thread:: JoinHandle ;
12
11
use std:: time:: Duration ;
12
+ use std:: {
13
+ env,
14
+ thread,
15
+ } ;
13
16
14
17
use anstream:: {
15
18
print,
@@ -49,6 +52,53 @@ pub enum SpinnerComponent {
49
52
Spinner ,
50
53
}
51
54
55
+ /// Play the terminal bell notification sound
56
+ /// This is a separate function to make it easier to call from multiple places
57
+ pub fn play_notification_bell ( ) {
58
+ // Check if we should play the bell based on terminal type
59
+ if should_play_bell ( ) {
60
+ print ! ( "\x07 " ) ; // ASCII bell character
61
+ stdout ( ) . flush ( ) . unwrap ( ) ;
62
+ }
63
+ }
64
+
65
+ /// Determine if we should play the bell based on terminal type
66
+ fn should_play_bell ( ) -> bool {
67
+ // Get the TERM environment variable
68
+ if let Ok ( term) = env:: var ( "TERM" ) {
69
+ // List of terminals known to handle bell character well
70
+ let bell_compatible_terms = [
71
+ "xterm" ,
72
+ "xterm-256color" ,
73
+ "screen" ,
74
+ "screen-256color" ,
75
+ "tmux" ,
76
+ "tmux-256color" ,
77
+ "rxvt" ,
78
+ "rxvt-unicode" ,
79
+ "linux" ,
80
+ "konsole" ,
81
+ "gnome" ,
82
+ "gnome-256color" ,
83
+ "alacritty" ,
84
+ "iterm2" ,
85
+ ] ;
86
+
87
+ // Check if the current terminal is in the compatible list
88
+ for compatible_term in bell_compatible_terms. iter ( ) {
89
+ if term. starts_with ( compatible_term) {
90
+ return true ;
91
+ }
92
+ }
93
+
94
+ // For other terminals, don't play the bell
95
+ return false ;
96
+ }
97
+
98
+ // If TERM is not set, default to not playing the bell
99
+ false
100
+ }
101
+
52
102
impl Spinner {
53
103
pub fn new ( components : Vec < SpinnerComponent > ) -> Self {
54
104
let ( sender, recv) = channel :: < Option < String > > ( ) ;
0 commit comments