Documentation
¶
Index ¶
- Variables
- func AnySlice[T any](in []T) []any
- func ConvertSliceToAny[T any](ts []T) []any
- func ConvertStringSlicePtr[T ~string](ss []string) *[]T
- func Deref[T any](val *T) T
- func DerefStr[T ~string](val *T) string
- func DisplayPath(path string) string
- func ExpandPath(path string) string
- func Must[T any](v T, err error) T
- func PtrIfNonZero[T comparable](val T) *T
- func ReadAll(ctx context.Context, stdin io.Reader) (string, error)
- func ReadLine(ctx context.Context, stdin io.Reader) (string, error)
- func ReadPassword(ctx context.Context, stdin io.Reader) (string, error)
- func SerializeToJSON(w io.Writer, v any) error
- func SerializeToYAML(w io.Writer, v any) error
- func TryUnwrapFile(w io.Writer) io.Writer
- type Duration
- type TermWriter
Constants ¶
This section is empty.
Variables ¶
var IsTerminal = func(w any) bool { if tw, ok := w.(*TermWriter); ok { return term.IsTerminal(int(tw.Fd())) } if f, ok := w.(*os.File); ok { return term.IsTerminal(int(f.Fd())) } return false }
IsTerminal is a helper for detecting whether an io.Writer or io.Reader is an interactive terminal / TTY. It is a variable so that tests can override it (similar to common.OpenBrowser).
Functions ¶
func ConvertSliceToAny ¶
ConvertSliceToAny converts a slice of some type to slice of any. Returns nil if the input slice is nil.
func ConvertStringSlicePtr ¶
ConvertStringSlicePtr converts a slice of strings to a pointer to another string-like type. Returns nil if the input slice is nil.
func DisplayPath ¶ added in v0.14.0
DisplayPath replaces $HOME with ~ in path for compact display.
func ExpandPath ¶
ExpandPath expands environment variables and tilde in file paths. It handles: - Empty paths (returns empty string) - Environment variable expansion (e.g., $HOME/config) - Home directory expansion (e.g., ~/config or ~) - Path normalization for cross-platform compatibility
func PtrIfNonZero ¶
func PtrIfNonZero[T comparable](val T) *T
func SerializeToYAML ¶
SerializeToYAML serializes data to YAML format.
This function first marshals to JSON, then unmarshals and encodes to YAML. This approach ensures that:
- Structs from third-party libraries or generated code that only include json: struct tags (without yaml: tags) are correctly marshaled
- JSON and YAML marshaling produce consistent output, both respecting the same json: tags and omitempty directives
func TryUnwrapFile ¶
TryUnwrapFile attempts to extract the underlying *os.File from a writer. If the writer is a *TermWriter, the embedded *os.File is returned; if it is already an *os.File, it is returned as-is. Otherwise the original writer is returned unchanged. This is needed when passing writers to exec.Cmd, since os/exec only passes file descriptors directly to child processes when the writer is an *os.File. Any other io.Writer causes os/exec to create a pipe, which breaks TTY detection in the child process.
Types ¶
type Duration ¶
Duration is a wrapper around time.Duration that allows it to be marshalled to/from JSON via the standard duration string format.
func (Duration) MarshalText ¶
Implements the encoding.TextMarshaler interface.
func (*Duration) UnmarshalText ¶
Implements the encoding.TextUnmarshaler interface.
type TermWriter ¶
type TermWriter struct {
*os.File
ColorProfile *colorprofile.Writer
}
TermWriter embeds *os.File so that Fd(), Read(), and Close() are promoted automatically (satisfying bubbletea's term.File interface for terminal detection), while overriding Write() to route through a colorprofile.Writer for automatic color downsampling.
func NewTermWriter ¶
func NewTermWriter(f *os.File) *TermWriter
NewTermWriter creates a TermWriter that writes through a colorprofile.Writer while exposing the underlying file's terminal capabilities.