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
+13.6k Golang : Linear algebra and matrix calculation example
+11.5k Golang : How to use if, eq and print properly in html template
+18.1k Golang : How to make a file read only and set it to writable again?
+8.5k Golang : Configure Apache and NGINX to access your Go service example
+7.4k Golang : Dealing with postal or zip code example
+6.4k Apt-get to install and uninstall Golang
+9.5k Golang : Create unique title slugs example
+20k Golang : Append content to a file
+36.7k Golang : How to split or chunking a file to smaller pieces?
+10.6k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+5k Javascript : How to get width and height of a div?
+8.4k Golang : Emulate NumPy way of creating matrix example