tty

package
v12.120.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 30

Documentation

Overview

Package tty provides methods for working with TTY

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHeight

func GetHeight() int

GetHeight returns window height

Example
height := GetHeight()

if height == -1 {
	fmt.Println("Can't detect window size")
	return
}

fmt.Printf("Window height: %d\n", height)
Output:

func GetSize

func GetSize() (int, int)

GetSize returns window width and height

Example
width, height := GetSize()

if width == -1 && height == -1 {
	fmt.Println("Can't detect window size")
	return
}

fmt.Printf("Window size: %d x %d\n", width, height)
Output:

func GetWidth

func GetWidth() int

GetWidth returns window width

Example
width := GetWidth()

if width == -1 {
	fmt.Println("Can't detect window size")
	return
}

fmt.Printf("Window width: %d\n", width)
Output:

func IsFakeTTY

func IsFakeTTY() bool

IsFakeTTY returns true is fake TTY is used

func IsSystemd added in v12.112.1

func IsSystemd() bool

IsSystemd returns true if process started by systemd

Example
if IsSystemd() {
	fmt.Println("This process started by systemd")
}
Output:

func IsTMUX added in v12.91.0

func IsTMUX() (bool, error)

IsTMUX returns true if we are currently working in tmux

Example
isTmux, err := IsTMUX()

if err != nil {
	panic(err.Error())
}

if isTmux {
	fmt.Println("App works in tmux")
} else {
	fmt.Println("App works in bare terminal")
}
Output:

func IsTTY

func IsTTY() bool

IsTTY returns true if current output device is TTY

Example
if IsTTY() {
	fmt.Println("Output is TTY")
} else {
	fmt.Println("Output is not TTY")
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL