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
+8.9k Golang : Compare files modify date example
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+14k Golang : rune literal not terminated error
+6.8k Javascript : Put image into Chrome browser's console
+8.3k Golang : How to generate Code 39 barcode?
+4.8k PHP : Get client IP address
+22.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+12k Golang : Linear algebra and matrix calculation example
+15.8k Golang : XML to JSON example
+22.8k Golang : Daemonizing a simple web server process example
+6.2k Golang : How to stop user from directly running an executable file?
+24.4k Golang : How to write CSV data to file