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.9k Golang : Replace a parameter's value inside a configuration file example
+6.1k Linux/Unix : Commands that you need to be careful about
+55.2k Golang : Unmarshal JSON from http response
+21.6k Golang : GORM create record or insert new record into database example
+6.5k Elasticsearch : Shutdown a local node
+5.8k Golang : Launching your executable inside a console under Linux
+13.4k Golang : Count number of runes in string
+8.1k Golang : Tell color name with OpenCV example
+7.3k Golang : Calculate how many weeks left to go in a given year
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+10.9k Golang : How to transmit update file to client by HTTP request example
+17.8k Golang : Login and logout a user after password verification and redirect example