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
+12.5k Golang : How to check if a file is hidden?
+6.4k Golang : Rename part of filename
+5.5k Unix/Linux : Use netstat to find out IP addresses served by your website server
+12.3k Golang : Strings comparison
+5.7k Golang : Reverse by word
+15.5k Golang : How to generate QR codes?
+8.2k Golang : Read file with ioutil
+7.3k Useful methods to access blocked websites
+14.2k Golang : Get current time from the Internet time server(ntp) example
+8.6k Golang : Turn string or text file into slice example
+12.3k Golang : Verify token from Google Authenticator App
+34k Golang : How to split or chunking a file to smaller pieces?