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.5k Golang : Get input from keyboard
+25.8k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+11.1k Golang : How to display image file or expose CSS, JS files from localhost?
+9.9k Use systeminfo to find out installed Windows Hotfix(s) or updates
+11.9k Golang : Generate Code128 barcode
+32.6k Golang : convert(cast) bytes to string
+5.6k Restart Apache or Nginx web server without password prompt
+3.7k Facebook : How to place save to Facebook button on your website
+3.8k Unix/Linux : How to pipe/save output of a command to file?
+80.6k Golang : How to convert character to ASCII and back
+14.4k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+7.7k Golang : How to get username from email address