Golang : Get terminal width and height example
Problem :
You want to find out a terminal/console's width and height to calibrate your Golang text based program display. How to do that?
Solution :
Use the GoTerm package to determine the terminal dimension. For example :
package main
import (
"fmt"
"github.com/buger/goterm"
)
func main() {
terminalHeight := goterm.Height()
terminalWidth := goterm.Width()
fmt.Println("Terminal height : ", terminalHeight)
fmt.Println("Terminal width : ", terminalWidth)
}
Sample output :
Terminal height : 50
Terminal width : 139
References :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.8k Golang : Get sub string example
+15k Golang : Get all local users and print out their home directory, description and group id
+6.9k Golang : Get Alexa ranking data example
+12.8k Golang : Calculate elapsed years or months since a date
+15.3k Golang : Validate hostname
+22.3k Golang : Convert Unix timestamp to UTC timestamp
+19k Mac OSX : Homebrew and Golang
+20.1k nginx: [emerg] unknown directive "passenger_enabled"
+18.9k Golang : Check if directory exist and create if does not exist
+4.7k Javascript : How to get width and height of a div?
+22.4k Golang : Strings to lowercase and uppercase example
+16k Golang : convert string or integer to big.Int type