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
+26k Golang : Smarter Error Handling with strings.Contains()
+11.5k Golang : Convert(cast) int to int64
+8.7k Use systeminfo to find out installed Windows Hotfix(s) or updates
+12.6k Golang : Get current time from the Internet time server(ntp) example
+7.6k Golang : Eroding and dilating image with OpenCV example
+6.6k Golang : How to extract video or image files from html source code
+16.9k Golang : Example for DSA(Digital Signature Algorithm) package functions
+17.1k Golang : Execute shell command
+11.8k Golang : Find network of an IP address
+4.2k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+10.3k Golang : Convert int(year) to time.Time type
+9.4k Golang : Convert decimal number(integer) to IPv4 address