https://github.com/jftuga/termsize
Go module to return the terminal width and height
https://github.com/jftuga/termsize
Last synced: 8 months ago
JSON representation
Go module to return the terminal width and height
- Host: GitHub
- URL: https://github.com/jftuga/termsize
- Owner: jftuga
- License: bsd-3-clause
- Created: 2020-12-29T17:01:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-17T13:34:54.000Z (over 5 years ago)
- Last Synced: 2025-01-29T23:29:57.574Z (over 1 year ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# termsize
Go module to return the terminal width and height
The [Releases Page](https://github.com/jftuga/termsize/releases) contains command-line binaries for Windows, MacOS and Linux.
## NOTES
When a terminal is not available such as when using a pipe or redirecting to a file, then the `DefaultWidth` and
`DefaultHeight` as defined in `defaults.go` will be used. These defaults can be changed by setting
`termsize.DefaultWidth` and `termsize.DefaultHeight`.
## INSTALL
Go version 1.16 or newer is required for compilation.
```
go get github.com/jftuga/termsize
```
## ACKNOWLEDGEMENTS
This code is adapted from https://github.com/jessevdk/go-flags.
* [BSD-3-Clause License](https://github.com/jftuga/termsize/blob/main/LICENSE)
## Example
```go
// Tested on Windows 10, Raspberry Pi OS Linux, and MacOS Big Sur 11.1
package main
import (
"fmt"
"github.com/jftuga/termsize"
)
func main() {
termsize.DefaultHeight = 133
w := termsize.Width()
h := termsize.Height()
fmt.Printf("%dx%d\n", w, h)
}
```
## Output
```
PS C:\termsize> .\termsize.exe
133x46
```