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
+10.2k Golang : Create matrix with Gonum Matrix package example
+9.9k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+33.4k Golang : Create x509 certificate, private and public keys
+6.8k Golang : Squaring elements in array
+6k PHP : Proper way to get UTF-8 character or string length
+26.9k Golang : dial tcp: too many colons in address
+50.2k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+6.8k Golang : Check if one string(rune) is permutation of another string(rune)
+13.2k Golang : Query string with space symbol %20 in between
+9.1k Facebook : Getting the friends list with PHP return JSON format
+8.4k Golang : Executing and evaluating nested loop in html template
+5.3k Javascript : How to refresh page with JQuery ?