Skip to content
Myr

tty.go

This file

Path

internal/tty/tty.go

27 lines · 616 bytes · Go

Last changed by

chore: update to bubbletea v2 (#1112)Drew Smirnoffbefore adoptionf6dd28e

History of this file

Take it

1// Package tty provides tty-aware printing.2package tty34import (5	"fmt"6	"io"7	"os"8	"sync"910	"github.com/charmbracelet/colorprofile"11)1213var stdout = sync.OnceValue(func() io.Writer {14	return colorprofile.NewWriter(os.Stdout, os.Environ())15})1617// Writer returns a writer to stdout that downgrades or strips ansi18// sequences according to the environment (NO_COLOR, CLICOLOR, CLICOLOR_FORCE)19// and the capabilities of the terminal.20func Writer() io.Writer {21	return stdout()22}2324// Println handles println, striping ansi sequences if stdout is not a tty.25func Println(s string) {26	_, _ = fmt.Fprintln(stdout(), s)27}