GitShow/sindresorhus/terminal-size
sindresorhus

terminal-size

Reliably get the terminal window size

by sindresorhus
Star on GitHubForknpm

JavaScript

148 stars17 forks11 contributorsQuiet · 6mo agoSince 2016v4.0.1MIT

Meet the team

See all 11 on GitHub →
sindresorhus
sindresorhus35 contributions
bndnsmth
bndnsmth1 contribution
coreyfarrell
coreyfarrell1 contribution
BendingBender
BendingBender1 contribution
fabiospampinato
fabiospampinato1 contribution
ianobermiller
ianobermiller1 contribution
Richienb
Richienb1 contribution
rvagg
rvagg1 contribution

Languages

View on GitHub →
JavaScript96.8%
TypeScript3.2%

Commit activity

Last 12 weeks · 0 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
85
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent PRs & issues

Quiet · 2 discussions · Last activity 6mo ago
See all on GitHub →
laser
`terminalSize()` leaks a `/dev/tty` file descriptor on LinuxOpenIssue

When both stdout and stderr are redirected and / are unset, falls through to . The current implementation opens and constructs a , but closes neither descriptor deterministically. On Linux, libuv normally reopens the TTY before attaching it to the stream handle. Consequently, each call can retain both the descriptor returned by and libuv’s reopened descriptor. One concrete trigger is an ink-based application running in a Docker container with a controlling TTY while its stdout and stderr are redirected inside the container. Ink falls back to terminal-size when terminal dimensions are unavailable and may invoke it repeatedly during rendering. Reproduction Using 4.0.1 on Node.js 24.18.0, Debian 12: Observed: The descriptors remained open after forced garbage collection and event-loop turns. Repeated calls can therefore exhaust the process’s descriptor limit and interfere with unrelated I/O. Cleanup complication The straightforward cleanup attempted in PR #27 was: 1. Retain the descriptor passed to . 2. Call . 3. Close the retained descriptor in a block. That is unsafe under descriptor pressure. libuv normally reopens the TTY, but if reopening fails, it retains the supplied descriptor. then closes that descriptor synchronously. Another native thread can reuse its number before the block calls , causing the latter to close an unrelated descriptor. The documented Node.js API does not expose whether libuv duplicated or retained the supplied descriptor, so the caller cannot safely decide which descriptors it still owns. Expected behavior Repeated calls should: Return the controlling terminal’s dimensions. Keep the process’s descriptor count stable. Never close unrelated descriptors under descriptor pressure. The regression test should run a redirected child inside a real pseudo-terminal in Linux CI rather than skipping when the CI process lacks a controlling TTY. This issue is Linux-specific. macOS follows a different libuv path and should be handled separately.

laser · 4w ago

Recent fixes

View closed PRs →
laser
Fix /dev/tty file descriptor leak in devTty()MergedPR

Calling terminalSize() repeatedly on Linux leaked a /dev/tty file descriptor on each invocation, eventually exhausting the process's fd table.

laser · 4w ago
pablopunk
Process suspended when stdout and stderr are redirected and the process is daemonizedClosedIssue

So trying to fix this issue I found that in this line of stops the execution: Reproduce With the binary, execute a script: And executing like this: This doesn't happen when you don't run the process in the background (so, without the last ): This could be an error in or in the binary, I have no clue.

pablopunk · 6mo ago
Velociraptor45
Window size detection for Git Bash pager falls back to default valuesClosedIssue

Hey there, this is kind of a follow-up to #22. It works fine for the normal git bash window, however when opening e.g. a less pager in that window, it falls back to the default 80/24 values. I've debugged it and I think I found a bug, but I'd like your confirmation on this. STR 1. Comment out the following in the to simulate the pager without having to actually have a pager (line 60 is where we'd like to go): !grafik 2. Temporarily add the following to the bottom of the to execute the size function upon calling the script 3. Execute the in a Git Bash and see that it's not returning the correct window size. !grafik Possible Solution The index.js contains this line: !grafik The is duplicated and when I replace the second one with , it's working fine. !grafik Resulting in correct window sizes: !grafik Any opinion on this?

Velociraptor45 · 11mo ago
Structured data for AI agents

Repository: sindresorhus/terminal-size. Description: Reliably get the terminal window size Stars: 148, Forks: 17. Primary language: JavaScript. Languages: JavaScript (96.8%), TypeScript (3.2%). License: MIT. Latest release: v4.0.1 (6mo ago). Open PRs: 0, open issues: 2. Last activity: 6mo ago. Community health: 85%. Top contributors: sindresorhus, bndnsmth, coreyfarrell, BendingBender, fabiospampinato, ianobermiller, Richienb, rvagg, shinnn, styfle and others.

·@ofershap

Replace github.com with gitshow.dev