main
1//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos
2// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos
3
4package tea
5
6import (
7 "fmt"
8 "os"
9 "os/signal"
10 "syscall"
11
12 "github.com/charmbracelet/x/term"
13)
14
15func (p *Program) initInput() (err error) {
16 // Check if input is a terminal
17 if f, ok := p.input.(term.File); ok && term.IsTerminal(f.Fd()) {
18 p.ttyInput = f
19 p.previousTtyInputState, err = term.MakeRaw(p.ttyInput.Fd())
20 if err != nil {
21 return fmt.Errorf("error entering raw mode: %w", err)
22 }
23 }
24
25 if f, ok := p.output.(term.File); ok && term.IsTerminal(f.Fd()) {
26 p.ttyOutput = f
27 }
28
29 return nil
30}
31
32func openInputTTY() (*os.File, error) {
33 f, err := os.Open("/dev/tty")
34 if err != nil {
35 return nil, fmt.Errorf("could not open a new TTY: %w", err)
36 }
37 return f, nil
38}
39
40const suspendSupported = true
41
42// Send SIGTSTP to the entire process group.
43func suspendProcess() {
44 c := make(chan os.Signal, 1)
45 signal.Notify(c, syscall.SIGCONT)
46 _ = syscall.Kill(0, syscall.SIGTSTP)
47 // blocks until a CONT happens...
48 <-c
49}