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
+5.9k Golang : Missing Subversion command
+8.1k Golang : Oanda bot with Telegram and RSI example
+10.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+22.6k Golang : Round float to precision example
+5k Golang : Customize scanner.Scanner to treat dash as part of identifier
+18.3k Golang : Logging with logrus
+6.1k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+13.7k Golang : Gin framework accept query string by post request example
+7.7k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+11k Golang : Roll the dice example
+20.3k Golang : Pipe output from one os.Exec(shell command) to another command