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.1k Golang : Convert file unix timestamp to UTC time example
+11.3k Golang : Simple file scaning and remove virus example
+14.1k Golang : Recombine chunked files example
+14.2k Golang : Send email with attachment(RFC2822) using Gmail API example
+12.2k Elastic Search : Return all records (higher than default 10)
+5.4k Golang : Detect words using using consecutive letters in a given string
+30k Golang : How to verify uploaded file is image or allowed file types
+8.6k Golang : Gaussian blur on image and camera video feed examples
+6.8k Restart Apache or Nginx web server without password prompt
+9.7k Golang : Check if user agent is a robot or crawler example
+17.1k Golang : Get future or past hours, minutes or seconds