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
+26.5k Get file path of temporary file in Go
+8.4k Golang : Copy map(hash table) example
+3.8k Golang : Experimental Jawi programming language
+4.6k Linux/Unix/PHP : Restart PHP-FPM
+5.5k Golang : How to determine if request or crawl is from Google robots
+16k Golang : How to save log messages to file?
+3.7k MariaDB/MySQL : How to get version information
+16.4k Golang : How to log each HTTP request to your web server?
+10.7k Golang : md5 hash of a string
+4.8k nginx : force all pages to be SSL
+12.8k Golang : How to check if your program is running in a terminal
+23.4k Golang : Change file read or write permission example