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 : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+5.7k Javascript : How to refresh page with JQuery ?
+17.1k Golang : How to save log messages to file?
+10.1k Golang : Read file and convert content to string
+14.3k Golang : Convert IP version 6 address to integer or decimal number
+13.5k Golang : Get constant name from value
+13.8k Golang : Activate web camera and broadcast out base64 encoded images
+12.5k Golang : Extract part of string with regular expression
+6.9k Golang : Decode XML data from RSS feed
+4.6k Java : Generate multiplication table example
+5.5k Gogland : Datasource explorer
+16.5k Golang : How to implement two-factor authentication?