Documentation
¶
Overview ¶
Package terminal provides terminal detection and size queries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Height ¶
Height returns the height of the terminal connected to `f`, or 0 if `f` is nil or not a terminal.
Example ¶
Height returns 0 when the file is nil or not connected to a terminal.
package main
import (
"fmt"
"github.com/gechr/x/terminal"
)
func main() {
fmt.Println(terminal.Height(nil))
}
Output: 0
func Is ¶
Is returns true if the given file is a terminal. Returns false for nil files.
Example ¶
A pipe is not a terminal, and nil files are always reported as non-terminals.
package main
import (
"fmt"
"os"
"github.com/gechr/x/terminal"
)
func main() {
r, w, err := os.Pipe()
if err != nil {
panic(err)
}
defer r.Close()
defer w.Close()
fmt.Println(terminal.Is(r))
fmt.Println(terminal.Is(w))
fmt.Println(terminal.Is(nil))
}
Output: false false false
func Size ¶
Size returns the (width, height) of the terminal connected to `f` in cells, or (0, 0) if `f` is nil or not a terminal.
Example ¶
Size returns (0, 0) when the file is nil or not connected to a terminal.
package main
import (
"fmt"
"github.com/gechr/x/terminal"
)
func main() {
w, h := terminal.Size(nil)
fmt.Println(w, h)
}
Output: 0 0
func Width ¶
Width returns the width of the terminal connected to `f`. Returns 0 if `f` is nil or not a terminal.
Example ¶
Width returns 0 when the file is nil or not connected to a terminal.
package main
import (
"fmt"
"github.com/gechr/x/terminal"
)
func main() {
fmt.Println(terminal.Width(nil))
}
Output: 0
Types ¶
This section is empty.