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
+11.5k Golang : GTK Input dialog box examples
+35.7k Golang : Converting a negative number to positive number
+62.3k Golang : Convert HTTP Response body to string
+5.5k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+12k Golang : Get month name from date example
+5.6k Facebook : How to force facebook to scrape latest URL link data?
+7.3k Golang : Convert(cast) io.Reader type to string
+25.9k Golang : Convert(cast) string to uint8 type and back to string
+11.1k Android Studio : Create custom icons for your application example
+17.8k Golang : Check if a directory exist or not
+5.9k Golang : How to write backslash in string?
+14.5k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name