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
+7.4k Golang : How to iterate a slice without using for loop?
+19.3k Golang : Check whether a network interface is up on your machine
+4.8k Golang : How to pass data between controllers with JSON Web Token
+26.2k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+7k Golang : Fibonacci number generator examples
+10.2k Golang : Edge detection with Sobel method
+12.8k Android Studio : Highlight ImageButton when pressed on example
+9.6k Javascript : Read/parse JSON data from HTTP response
+12.2k Golang : Pagination with go-paginator configuration example
+13.5k Golang : Verify token from Google Authenticator App
+11.7k Golang : Simple file scaning and remove virus example
+6.1k PHP : How to check if an array is empty ?