Skip to content

Commit c14ef48

Browse files
authored
fix: Show error message when exiting tmux session without detaching (#110)
Prompted by #109, this change educates the user to use `Ctrl-Q` instead of `Ctrl-C/Ctrl-D` to detach from a session. https://github.com/user-attachments/assets/8a3af889-db17-4621-8a19-dfb90e2a2525 Fixes #109
1 parent c660406 commit c14ef48

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

session/tmux/tmux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ func (t *TmuxSession) Attach() (chan struct{}, error) {
244244
go func() {
245245
defer t.wg.Done()
246246
_, _ = io.Copy(os.Stdout, t.ptmx)
247+
// When io.Copy returns, it means the connection was closed
248+
// This could be due to normal detach or Ctrl-D
249+
// Check if the context is done to determine if it was a normal detach
250+
select {
251+
case <-t.ctx.Done():
252+
// Normal detach, do nothing
253+
default:
254+
// If context is not done, it was likely an abnormal termination (Ctrl-D)
255+
// Print warning message
256+
fmt.Fprintf(os.Stderr, "\n\033[31mError: Session terminated without detaching. Use Ctrl-Q to properly detach from tmux sessions.\033[0m\n")
257+
}
247258
}()
248259

249260
go func() {

0 commit comments

Comments
 (0)