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.7k Golang : Find age or leap age from date of birth example
+9.4k Golang : Timeout example
+8.3k Prevent Write failed: Broken pipe problem during ssh session with screen command
+9.3k Golang : How to check if a string with spaces in between is numeric?
+8.9k Android Studio : Image button and button example
+19.6k Golang : Example for DSA(Digital Signature Algorithm) package functions
+48.2k Golang : How to convert JSON string to map and slice
+15.3k Golang : Get timezone offset from date or timestamp
+7k Nginx : Password protect a directory/folder
+5.2k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+8.3k Golang : Emulate NumPy way of creating matrix example
+17.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography