use the higher-level "IoctlGetWinsize" in logger

This commit is contained in:
Evan Wallace
2020-09-19 11:03:42 -07:00
parent 3444fa6dad
commit 80713c6735
4 changed files with 11 additions and 24 deletions

View File

@@ -1,5 +1,11 @@
# Changelog
## Unreleased
* Fix compile error due to missing `unix.SYS_IOCTL` in the latest `golang.org/x/sys` ([#396](https://github.com/evanw/esbuild/pull/396))
The `unix.SYS_IOCTL` export was apparently removed from `golang.org/x/sys` recently, which affected code in esbuild that gets the width of the terminal. This code now uses another method of getting the terminal width. The fix was contributed by [@akayj](https://github.com/akayj).
## 0.7.2
* Transform arrow functions to function expressions with `--target=es5` ([#182](https://github.com/evanw/esbuild/issues/182) and [#297](https://github.com/evanw/esbuild/issues/297))

View File

@@ -1,6 +1,6 @@
ESBUILD_VERSION = $(shell cat version.txt)
esbuild: cmd/esbuild/*.go pkg/*/*.go internal/*/*.go
esbuild: cmd/esbuild/*.go pkg/*/*.go internal/*/*.go go.mod
go build "-ldflags=-s -w" ./cmd/esbuild
npm/esbuild-wasm/esbuild.wasm: cmd/esbuild/*.go pkg/*/*.go internal/*/*.go

View File

@@ -4,21 +4,12 @@ package logger
import (
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
const SupportsColorEscapes = true
type winsize struct {
ws_row uint16
ws_col uint16
ws_xpixel uint16
ws_ypixel uint16
}
func GetTerminalInfo(file *os.File) (info TerminalInfo) {
fd := file.Fd()
@@ -28,9 +19,8 @@ func GetTerminalInfo(file *os.File) (info TerminalInfo) {
info.UseColorEscapes = true
// Get the width of the window
w := new(winsize)
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(w))); err == 0 {
info.Width = int(w.ws_col)
if w, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ); err == nil {
info.Width = int(w.Col)
}
}

View File

@@ -4,20 +4,12 @@ package logger
import (
"os"
"unsafe"
"golang.org/x/sys/unix"
)
const SupportsColorEscapes = true
type winsize struct {
ws_row uint16
ws_col uint16
ws_xpixel uint16
ws_ypixel uint16
}
func GetTerminalInfo(file *os.File) (info TerminalInfo) {
fd := file.Fd()
@@ -27,9 +19,8 @@ func GetTerminalInfo(file *os.File) (info TerminalInfo) {
info.UseColorEscapes = true
// Get the width of the window
w := new(winsize)
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, unix.TIOCGWINSZ, uintptr(unsafe.Pointer(w))); err == 0 {
info.Width = int(w.ws_col)
if w, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ); err == nil {
info.Width = int(w.Col)
}
}