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
+15.4k Golang : Validate hostname
+14.1k Golang : Chunk split or divide a string into smaller chunk example
+6.4k Golang : Combine slices of complex numbers and operation example
+10k Golang : Use regular expression to get all upper case or lower case characters example
+15.1k Golang : Get all local users and print out their home directory, description and group id
+44.6k Golang : Use wildcard patterns with filepath.Glob() example
+5k Golang : Issue HTTP commands to server and port example
+10.3k Golang : Generate random integer or float number
+5.9k PHP : Get client IP address
+4.8k Google : Block or disable caching of your website content
+11.2k Golang : How to use if, eq and print properly in html template
+18.5k Golang : Iterating Elements Over A List