tty_unix.go
This file
Path
tty_unix.go
47 lines · 1.1 KiB · Go
Last changed by
fix: add missing signal.Stop in suspendProcess to prevent signal channel leak (Closes #1673) (#1674)Cocoon-Breakbefore adoption729f05c
History of this fileTake it
1//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos2// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos34package tea56import (7 "fmt"8 "os"9 "os/signal"10 "syscall"1112 "github.com/charmbracelet/x/term"13)1415func (p *Program) initInput() (err error) {16 // Check if input is a terminal17 if f, ok := p.input.(term.File); ok && term.IsTerminal(f.Fd()) {18 p.ttyInput = f19 p.previousTtyInputState, err = term.MakeRaw(p.ttyInput.Fd())20 if err != nil {21 return fmt.Errorf("error entering raw mode: %w", err)22 }2324 // OPTIM: We can use hard tabs and backspaces to optimize cursor25 // movements. This is based on termios settings support and whether26 // they exist and enabled.27 p.checkOptimizedMovements(p.previousTtyInputState)28 }2930 if f, ok := p.output.(term.File); ok && term.IsTerminal(f.Fd()) {31 p.ttyOutput = f32 }3334 return nil35}3637const suspendSupported = true3839// Send SIGTSTP to the entire process group.40func suspendProcess() {41 c := make(chan os.Signal, 1)42 signal.Notify(c, syscall.SIGCONT)43 defer signal.Stop(c)44 _ = syscall.Kill(0, syscall.SIGTSTP)45 // blocks until a CONT happens...46 <-c47}