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
+11k Golang : Get month name from date example
+4.8k Golang : Error handling methods
+5.4k Golang : Convert an executable file into []byte example
+3.7k Linux : sudo yum updates not working
+14.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+4.5k Golang : Shortening import identifier
+12.3k Golang : Set image canvas or background to transparent
+16.1k Golang : delete and modify XML file content
+6.4k Golang : Lock executable to a specific machine with unique hash of the machine
+13.9k Golang : How to get Unix file descriptor for console and file
+20.4k Golang : Convert seconds to minutes and remainder seconds
+17.3k Golang : Padding data for encryption and un-padding data for decryption