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
+8.8k Golang : Combine slices but preserve order example
+25.5k Golang : Get current file path of a file or executable
+4.2k Detect if Google Analytics and Developer Media are loaded properly or not
+7.1k Android Studio : Hello World example
+32k Golang : How to convert(cast) string to IP address?
+14k Golang : Convert spaces to tabs and back to spaces example
+10.3k Golang : How to tokenize source code with text/scanner package?
+16.1k Golang : How to login and logout with JWT example
+8.4k Golang : Qt splash screen with delay example
+6.2k Golang : Convert Chinese UTF8 characters to Pin Yin
+17.2k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+32.4k Golang : Convert []string to []byte examples