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 IsDark ¶ added in v0.3.4
IsDark reports (dark, ok) for the controlling terminal. `ok` is false if no standard stream is a terminal or the terminal does not respond to the background-color query, in which case the first result is meaningless.
Example ¶
IsDark reports ok=false when no standard stream is connected to a terminal, since there is no background to query.
package main
import (
"fmt"
"github.com/gechr/x/terminal"
)
func main() {
dark, ok := terminal.IsDark()
switch {
case !ok:
fmt.Println("no terminal detected")
case dark:
fmt.Println("dark")
default:
fmt.Println("light")
}
}
Output: no terminal detected
func IsLight ¶ added in v0.3.4
IsLight reports (light, ok) for the controlling terminal. `ok` is false if no standard stream is a terminal or the terminal does not respond to the background-color query, in which case the first result is meaningless.
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.