A tiny, dependency-free Go library for reading terminal width and height (columns × rows) on the machine your process is attached to.
- No third-party modules — only the standard library
- Linux, macOS, BSDs, and Windows — one import, two files behind build tags
- ~100 lines of Go — uses ioctl on Unix,
GetConsoleScreenBufferInfoon Windows
- Microsoft projects (Azure/azure-dev)
- AWS-related tooling (awslabs/diagram-as-code, aws-cloudformation/rain)
- 200+ public repositories
x/term (and the wider x/ family) is the right choice when you want a full terminal feature set — raw mode, bracketed paste, cursor APIs, and more. It pulls in golang.org/x/sys and a larger API surface.
consolesize-go is for when you only need window size: one function, no extra module graph, and nothing else to learn or audit. That is a deliberate trade-off, not a knock on x/term.
go get github.com/nathan-fiscaletti/consolesize-gopackage main
import (
"fmt"
"github.com/nathan-fiscaletti/consolesize-go"
)
func main() {
cols, rows := consolesize.GetConsoleSize()
fmt.Printf("columns: %d, rows: %d\n", cols, rows)
}GetConsoleSize returns (columns, rows).
Minimal mains that only read terminal size are built side-by-side under sizecmp/: one links this module, the other links golang.org/x/term (which pulls x/sys). Both use the same go build flags.
The script strips symbols (-ldflags=-s -w) and uses -trimpath so paths on your machine do not affect the build. It prints byte sizes and the delta for your GOOS/GOARCH and Go toolchain. Exact numbers change across releases; the typical pattern is a smaller binary when you avoid x/term + x/sys for size-only callers. On an Apple M5 this saves ~17kb.
./sizecmp/compare.sh
go version: go version go1.26.1 darwin/arm64
GOOS=darwin GOARCH=arm64
flags: go build -ldflags=-s -w -trimpath
consolesize-go 1454754 bytes
golang.org/x/term 1471874 bytes
delta (x/term - consolesize-go) +17120 byteBased on: network/dependents as of April 6th, 2026.
- xo/usql
- TheZoraiz/ascii-image-converter
- xyproto/algernon
- neilotoole/sq
- fwdcloudsec/granted
- awslabs/diagram-as-code
- aws-cloudformation/rain
- xyproto/orbiton
- Azure/azure-dev
- pingcap/tiup
- mondoohq/mql
- common-fate/glide
- viamrobotics/rdk
- xyproto/gendesk
- Isan-Rivkin/surf
- arimatakao/mdx
- openshift/rosa
MIT — see LICENSE.