New Upstream Release - golang-github-mattn-go-tty

Ready changes

Summary

Merged new upstream version: 0.0.4 (was: 0.0.3).

Resulting package

Built on 2023-01-12T13:36 (took 7m28s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-mattn-go-tty-dev

Lintian Result

Diff

diff --git a/debian/changelog b/debian/changelog
index dd51cbc..25a8e28 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-mattn-go-tty (0.0.4-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Thu, 12 Jan 2023 13:29:55 -0000
+
 golang-github-mattn-go-tty (0.0.3-2) unstable; urgency=medium
 
   * Source-only upload.
diff --git a/go.mod b/go.mod
index 767e2af..49a9099 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,6 @@ go 1.14
 require (
 	github.com/mattn/go-colorable v0.1.4
 	github.com/mattn/go-isatty v0.0.10
-	github.com/mattn/go-runewidth v0.0.6
-	golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
+	github.com/mattn/go-runewidth v0.0.7
 	golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e
 )
diff --git a/go.sum b/go.sum
index 7a9ef11..a516a4a 100644
--- a/go.sum
+++ b/go.sum
@@ -3,10 +3,8 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
 github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
 github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
-github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
-github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
-golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
-golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
+github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
diff --git a/tty.go b/tty.go
index 13cb206..6c8e719 100644
--- a/tty.go
+++ b/tty.go
@@ -6,6 +6,8 @@ import (
 	"unicode"
 )
 
+var linefeed = []byte{'\n'}
+
 func Open() (*TTY, error) {
 	return open("/dev/tty")
 }
@@ -76,7 +78,7 @@ loop:
 			if len(rs) > 0 {
 				rs = rs[:len(rs)-1]
 				if displayType != displayNone {
-					tty.Output().WriteString("\b \b")
+					tty.Output().Write([]byte("\b \b"))
 				}
 			}
 		default:
@@ -84,9 +86,9 @@ loop:
 				rs = append(rs, r)
 				switch displayType {
 				case displayRune:
-					tty.Output().WriteString(string(r))
+					tty.Output().Write([]byte(string(r)))
 				case displayMask:
-					tty.Output().WriteString("*")
+					tty.Output().Write([]byte{'*'})
 				}
 			}
 		}
@@ -95,26 +97,26 @@ loop:
 }
 
 func (tty *TTY) ReadString() (string, error) {
-	defer tty.Output().WriteString("\n")
+	defer tty.Output().Write(linefeed)
 	return tty.readString(displayRune)
 }
 
 func (tty *TTY) ReadPassword() (string, error) {
-	defer tty.Output().WriteString("\n")
+	defer tty.Output().Write(linefeed)
 	return tty.readString(displayMask)
 }
 
 func (tty *TTY) ReadPasswordNoEcho() (string, error) {
-	defer tty.Output().WriteString("\n")
+	defer tty.Output().Write(linefeed)
 	return tty.readString(displayNone)
 }
 
 func (tty *TTY) ReadPasswordClear() (string, error) {
 	s, err := tty.readString(displayMask)
-	tty.Output().WriteString(
+	tty.Output().Write([]byte(
 		strings.Repeat("\b", len(s)) +
 			strings.Repeat(" ", len(s)) +
-			strings.Repeat("\b", len(s)))
+			strings.Repeat("\b", len(s))))
 	return s, err
 }
 
diff --git a/tty_bsd.go b/tty_bsd.go
index e0a51fc..8c01b6c 100644
--- a/tty_bsd.go
+++ b/tty_bsd.go
@@ -1,12 +1,13 @@
+//go:build darwin || dragonfly || freebsd || netbsd || openbsd
 // +build darwin dragonfly freebsd netbsd openbsd
 
 package tty
 
 import (
-	"syscall"
+	"golang.org/x/sys/unix"
 )
 
 const (
-	ioctlReadTermios  = syscall.TIOCGETA
-	ioctlWriteTermios = syscall.TIOCSETA
+	ioctlReadTermios  = unix.TIOCGETA
+	ioctlWriteTermios = unix.TIOCSETA
 )
diff --git a/tty_linux.go b/tty_linux.go
index 1b9e8ce..4ddbd78 100644
--- a/tty_linux.go
+++ b/tty_linux.go
@@ -1,8 +1,13 @@
+//go:build linux
 // +build linux
 
 package tty
 
+import (
+	"golang.org/x/sys/unix"
+)
+
 const (
-	ioctlReadTermios  = 0x5401 // syscall.TCGETS
-	ioctlWriteTermios = 0x5402 // syscall.TCSETS
+	ioctlReadTermios  = unix.TCGETS
+	ioctlWriteTermios = unix.TCSETS
 )
diff --git a/tty_solaris.go b/tty_solaris.go
new file mode 100644
index 0000000..1ea64da
--- /dev/null
+++ b/tty_solaris.go
@@ -0,0 +1,13 @@
+//go:build solaris
+// +build solaris
+
+package tty
+
+import (
+	"golang.org/x/sys/unix"
+)
+
+const (
+	ioctlReadTermios  = unix.TCGETS
+	ioctlWriteTermios = unix.TCSETS
+)
diff --git a/tty_sys5.go b/tty_sys5.go
deleted file mode 100644
index 7dc30ed..0000000
--- a/tty_sys5.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// +build solaris
-
-package tty
-
-import (
-	"golang.org/x/sys/unix"
-)
-
-const (
-	ioctlReadTermios  = unix.TCGETA
-	ioctlWriteTermios = unix.TCSETA
-)
diff --git a/tty_unix.go b/tty_unix.go
index 3cb9450..c9a8f17 100644
--- a/tty_unix.go
+++ b/tty_unix.go
@@ -1,5 +1,5 @@
-// +build !windows
-// +build !plan9
+//go:build !windows && !plan9
+// +build !windows,!plan9
 
 package tty
 
@@ -7,8 +7,6 @@ import (
 	"bufio"
 	"os"
 	"os/signal"
-	"syscall"
-	"unsafe"
 
 	"golang.org/x/sys/unix"
 )
@@ -17,7 +15,7 @@ type TTY struct {
 	in      *os.File
 	bin     *bufio.Reader
 	out     *os.File
-	termios syscall.Termios
+	termios unix.Termios
 	ss      chan os.Signal
 }
 
@@ -31,19 +29,23 @@ func open(path string) (*TTY, error) {
 	tty.in = in
 	tty.bin = bufio.NewReader(in)
 
-	out, err := os.OpenFile(path, syscall.O_WRONLY, 0)
+	out, err := os.OpenFile(path, unix.O_WRONLY, 0)
 	if err != nil {
 		return nil, err
 	}
 	tty.out = out
 
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tty.in.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&tty.termios))); err != 0 {
+	termios, err := unix.IoctlGetTermios(int(tty.in.Fd()), ioctlReadTermios)
+	if err != nil {
 		return nil, err
 	}
-	newios := tty.termios
-	newios.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXOFF
-	newios.Lflag &^= syscall.ECHO | syscall.ICANON /*| syscall.ISIG*/
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tty.in.Fd()), ioctlWriteTermios, uintptr(unsafe.Pointer(&newios))); err != 0 {
+	tty.termios = *termios
+
+	termios.Iflag &^= unix.ISTRIP | unix.INLCR | unix.ICRNL | unix.IGNCR | unix.IXOFF
+	termios.Lflag &^= unix.ECHO | unix.ICANON /*| unix.ISIG*/
+	termios.Cc[unix.VMIN] = 1
+	termios.Cc[unix.VTIME] = 0
+	if err := unix.IoctlSetTermios(int(tty.in.Fd()), ioctlWriteTermios, termios); err != nil {
 		return nil, err
 	}
 
@@ -64,8 +66,7 @@ func (tty *TTY) readRune() (rune, error) {
 func (tty *TTY) close() error {
 	signal.Stop(tty.ss)
 	close(tty.ss)
-	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tty.in.Fd()), ioctlWriteTermios, uintptr(unsafe.Pointer(&tty.termios)))
-	return err
+	return unix.IoctlSetTermios(int(tty.in.Fd()), ioctlWriteTermios, &tty.termios)
 }
 
 func (tty *TTY) size() (int, int, error) {
@@ -74,11 +75,11 @@ func (tty *TTY) size() (int, int, error) {
 }
 
 func (tty *TTY) sizePixel() (int, int, int, int, error) {
-	var dim [4]uint16
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tty.out.Fd()), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dim))); err != 0 {
+	ws, err := unix.IoctlGetWinsize(int(tty.out.Fd()), unix.TIOCGWINSZ)
+	if err != nil {
 		return -1, -1, -1, -1, err
 	}
-	return int(dim[1]), int(dim[0]), int(dim[2]), int(dim[3]), nil
+	return int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel), nil
 }
 
 func (tty *TTY) input() *os.File {
@@ -116,13 +117,13 @@ func (tty *TTY) raw() (func() error, error) {
 }
 
 func (tty *TTY) sigwinch() <-chan WINSIZE {
-	signal.Notify(tty.ss, syscall.SIGWINCH)
+	signal.Notify(tty.ss, unix.SIGWINCH)
 
 	ws := make(chan WINSIZE)
 	go func() {
 		defer close(ws)
 		for sig := range tty.ss {
-			if sig != syscall.SIGWINCH {
+			if sig != unix.SIGWINCH {
 				continue
 			}
 
diff --git a/tty_windows.go b/tty_windows.go
index 73ba6c7..3db0cf7 100644
--- a/tty_windows.go
+++ b/tty_windows.go
@@ -1,3 +1,4 @@
+//go:build windows
 // +build windows
 
 package tty
@@ -131,6 +132,7 @@ type TTY struct {
 	ws                chan WINSIZE
 	sigwinchCtx       context.Context
 	sigwinchCtxCancel context.CancelFunc
+	readNextKeyUp     bool
 }
 
 func readConsoleInput(fd uintptr, record *inputRecord) (err error) {
@@ -231,7 +233,14 @@ func (tty *TTY) readRune() (rune, error) {
 		}
 	case keyEvent:
 		kr := (*keyEventRecord)(unsafe.Pointer(&ir.event))
-		if kr.keyDown != 0 {
+		if kr.keyDown == 0 {
+			if kr.unicodeChar != 0 && tty.readNextKeyUp {
+				tty.readNextKeyUp = false
+				if 0x2000 <= kr.unicodeChar && kr.unicodeChar < 0x3000 {
+					return rune(kr.unicodeChar), nil
+				}
+			}
+		} else {
 			if kr.controlKeyState&altPressed != 0 && kr.unicodeChar > 0 {
 				tty.rs = []rune{rune(kr.unicodeChar)}
 				return rune(0x1b), nil
@@ -279,6 +288,11 @@ func (tty *TTY) readRune() (rune, error) {
 				}
 			}
 			switch vk {
+			case 0x12: // menu
+				if kr.controlKeyState&leftAltPressed != 0 {
+					tty.readNextKeyUp = true
+				}
+				return 0, nil
 			case 0x21: // page-up
 				tty.rs = []rune{0x5b, 0x35, 0x7e}
 				return rune(0x1b), nil

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/mattn/go-tty/tty_solaris.go

Files in first set of .debs but not in second

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/mattn/go-tty/tty_sys5.go

No differences were encountered in the control files

More details

Full run details