waitForEchoDisabled polls the TTY until echo mode is disabled or the timeout is reached. This is used in password and auth token tests to ensure that huh has configured the terminal before we send input.
(tty *os.File, timeout time.Duration)
| 961 | // timeout is reached. This is used in password and auth token tests to |
| 962 | // ensure that huh has configured the terminal before we send input. |
| 963 | func waitForEchoDisabled(tty *os.File, timeout time.Duration) error { |
| 964 | deadline := time.Now().Add(timeout) |
| 965 | for time.Now().Before(deadline) { |
| 966 | termios, err := unix.IoctlGetTermios(int(tty.Fd()), ioctlGetTermios) |
| 967 | if err != nil { |
| 968 | return fmt.Errorf("getting terminal attributes: %w", err) |
| 969 | } |
| 970 | if termios.Lflag&unix.ECHO == 0 { |
| 971 | return nil |
| 972 | } |
| 973 | time.Sleep(time.Millisecond) |
| 974 | } |
| 975 | return fmt.Errorf("timed out waiting for echo mode to be disabled") |
| 976 | } |
no test coverage detected