// SPDX-FileCopyrightText: 2026 Echolot contributors // SPDX-License-Identifier: GPL-3.0-or-later //go:build linux package system import ( "os" "syscall" "unsafe" ) // DisableEcho turns off terminal echo while a password is typed, returning a function that puts // the terminal back. Both are best-effort: when stdin is a pipe (the automation case) there is // no terminal to change and nothing to restore. func DisableEcho(f *os.File) (func(), error) { fd := f.Fd() var t syscall.Termios if _, _, errno := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TCGETS, uintptr(unsafe.Pointer(&t)), 0, 0, 0); errno != 0 { return nil, errno // not a terminal; nothing to do } original := t t.Lflag &^= syscall.ECHO if _, _, errno := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TCSETS, uintptr(unsafe.Pointer(&t)), 0, 0, 0); errno != 0 { return nil, errno } return func() { _, _, _ = syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TCSETS, uintptr(unsafe.Pointer(&original)), 0, 0, 0) }, nil }