Skip to content

nathan-fiscaletti/consolesize-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consolesize-go

Sponsor Me! GoDoc

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, GetConsoleScreenBufferInfo on Windows

Used by

Why not golang.org/x/term?

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.

Install

go get github.com/nathan-fiscaletti/consolesize-go

Usage

package 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).

Binary size

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 byte

Known projects using consolesize-go

Based on: network/dependents as of April 6th, 2026.

License

MIT — see LICENSE.

About

Used by AWS, Microsoft and 200+ other open-source projects. A tiny, dependency-free Go library for reading terminal width and height (columns × rows) on the machine your process is attached to.

Topics

Resources

License

Stars

Watchers

Forks

Contributors