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
+4.9k Facebook : How to place save to Facebook button on your website
+31.1k Golang : Interpolating or substituting variables in string examples
+11.8k Golang : Gorilla web tool kit secure cookie example
+39.2k Golang : How to iterate over a []string(array)
+7k Golang : Join lines with certain suffix symbol example
+23k Golang : untar or extract tar ball archive example
+6.7k Golang : How to validate ISBN?
+8k Golang : Reverse a string with unicode
+32.9k Golang : Regular Expression for alphanumeric and underscore
+13.8k Golang : Tutorial on loading GOB and PEM files
+15.4k Golang : Save(pipe) HTTP response into a file
+10.5k Golang : How to check if a website is served via HTTPS