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.6k Golang : Clean formatting/indenting or pretty print JSON result
+5.8k Golang : Progress bar with ∎ character
+12k Golang : Read large file with bufio.Scanner cause token too long error
+5.1k Golang : Ways to recover memory during run time.
+7.1k Golang : interface - when and where to use examples
+14.6k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+6.8k Golang : Identifying Golang HTTP client request
+16.1k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+27.9k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+4.8k Web : How to see your website from different countries?
+6.2k Golang : Format strings to SEO friendly URL example
+25.8k Golang : Copy directory - including sub-directories and files