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
+9.6k Golang : Changing a RGBA image number of channels with OpenCV
+11.3k Golang : Calculate Relative Strength Index(RSI) example
+10k Golang : Function wrapper that takes arguments and return result example
+9.6k Mac OSX : Get a process/daemon status information
+7.8k Gogland : Where to put source code files in package directory for rookie
+8.1k Setting $GOPATH environment variable for Unix/Linux and Windows
+19.6k Golang : Example for DSA(Digital Signature Algorithm) package functions
+11.3k CodeIgniter : How to check if a session exist in PHP?
+8k Golang : Get today's weekday name and calculate target day distance example
+17.9k Golang : Iterate linked list example
+8.3k How to show different content from website server when AdBlock is detected?