output

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package output provides user-facing output and file logging.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConsoleWriter is the writer used when no writer is specified.
	// This can be overridden in tests to capture output.
	DefaultConsoleWriter io.Writer = os.Stdout
)

Functions

func Branch added in v0.19.1

func Branch(name string, isCurrent bool) string

Branch renders a branch name, colored, with a "(current)" marker when isCurrent. Prefer BranchName/CurrentBranch when the condition is known at the call site.

func BranchName added in v0.22.0

func BranchName(name string) string

BranchName renders a non-current branch name, colored.

func BranchNameWithTrunk added in v0.22.0

func BranchNameWithTrunk(name string, isTrunk bool) string

BranchNameWithTrunk renders a non-current branch name, with trunk in a distinct color.

func BranchWithTrunk added in v0.19.1

func BranchWithTrunk(name string, isCurrent, isTrunk bool) string

BranchWithTrunk is like Branch but renders the trunk branch in a distinct color.

func CurrentBranch added in v0.22.0

func CurrentBranch(name string) string

CurrentBranch renders the current branch name with a "(current)" marker.

func Cyan added in v0.19.1

func Cyan(text string) string

Cyan renders text in cyan.

func Dim added in v0.19.1

func Dim(text string) string

Dim renders text in a dim/gray style.

func GetLogFilePath

func GetLogFilePath() string

GetLogFilePath returns the path to the log file. If STACKIT_LOG_FILE is set, uses that path. Otherwise, uses ~/.stackit/logs/stackit.log

func GetPanicLogPath

func GetPanicLogPath() string

GetPanicLogPath returns the path to the panic log file. This is a dedicated file for panic/crash information that is separate from regular logs to ensure panics are always findable. Uses ~/.stackit/logs/panic.log

func Green added in v0.19.1

func Green(text string) string

Green renders text in green.

func IconFrozen added in v0.19.1

func IconFrozen() string

IconFrozen returns the freeze status icon.

func IconLocked added in v0.19.1

func IconLocked() string

IconLocked returns the lock status icon.

func LogPanic

func LogPanic(panicValue any, stack string)

LogPanic writes panic information to a dedicated panic log file. This is separate from regular logging to ensure panics are always preserved and easily findable, even when the terminal is in a bad state. The function is designed to be safe to call in recovery handlers.

func Magenta added in v0.19.1

func Magenta(text string) string

Magenta renders text in magenta.

func NeedsRestack added in v0.19.1

func NeedsRestack(text string) string

NeedsRestack renders a "needs restack" hint.

func PRNumber added in v0.19.1

func PRNumber(prNumber int) string

PRNumber renders a pull-request number.

func Red added in v0.19.1

func Red(text string) string

Red renders text in red.

func RenderMarkdown added in v0.19.1

func RenderMarkdown(content string) string

RenderMarkdown renders markdown content for the terminal.

func Scope added in v0.19.1

func Scope(scope string) string

Scope renders a scope label.

func Yellow added in v0.19.1

func Yellow(text string) string

Yellow renders text in yellow.

Types

type ConsoleOutput

type ConsoleOutput struct {
	// contains filtered or unexported fields
}

ConsoleOutput implements Output for terminal output.

func NewConsoleOutput

func NewConsoleOutput(writer io.Writer, debugMode bool) *ConsoleOutput

NewConsoleOutput creates a new console output writer.

func NewDefaultOutput

func NewDefaultOutput() *ConsoleOutput

NewDefaultOutput creates a console output with stdout and debug from env.

func (*ConsoleOutput) Debug

func (c *ConsoleOutput) Debug(format string, args ...any)

Debug writes a debug message (only if debug mode is enabled).

func (*ConsoleOutput) DirectiveCD

func (c *ConsoleOutput) DirectiveCD(path string)

DirectiveCD outputs a shell integration directive for changing directory. This is always output (even in quiet mode) as the shell wrapper needs to parse it. If STACKIT_DIRECTIVE_FILE is set, writes to that file instead of stdout.

func (*ConsoleOutput) DirectiveRerun

func (c *ConsoleOutput) DirectiveRerun(args ...string)

DirectiveRerun outputs a shell integration directive to run a command after cd. If args are provided, runs "stackit <args...>". Otherwise re-runs the original command. This is always output (even in quiet mode) as the shell wrapper needs to parse it. If STACKIT_DIRECTIVE_FILE is set, writes to that file instead of stdout.

func (*ConsoleOutput) Error

func (c *ConsoleOutput) Error(format string, args ...any)

Error writes an error message with emoji prefix.

func (*ConsoleOutput) Info

func (c *ConsoleOutput) Info(format string, args ...any)

Info writes an info message.

func (*ConsoleOutput) IsQuiet

func (c *ConsoleOutput) IsQuiet() bool

IsQuiet returns whether quiet mode is enabled.

func (*ConsoleOutput) Newline

func (c *ConsoleOutput) Newline()

Newline writes an empty line.

func (*ConsoleOutput) Print

func (c *ConsoleOutput) Print(content string)

Print writes raw content without a newline.

func (*ConsoleOutput) Println

func (c *ConsoleOutput) Println(content string)

Println writes content with a newline.

func (*ConsoleOutput) SetQuiet

func (c *ConsoleOutput) SetQuiet(quiet bool)

SetQuiet enables or disables quiet mode.

func (*ConsoleOutput) Success

func (c *ConsoleOutput) Success(format string, args ...any)

Success writes a success message with emoji prefix.

func (*ConsoleOutput) Tip

func (c *ConsoleOutput) Tip(format string, args ...any)

Tip writes a tip message with emoji prefix.

func (*ConsoleOutput) Warn

func (c *ConsoleOutput) Warn(format string, args ...any)

Warn writes a warning message with emoji prefix.

type FileLogger

type FileLogger struct {
	// contains filtered or unexported fields
}

FileLogger implements Logger with file-based structured logging.

func NewFileLogger

func NewFileLogger(logFilePath string) (*FileLogger, error)

NewFileLogger creates a logger that writes to the specified file with rotation.

func (*FileLogger) Close

func (l *FileLogger) Close() error

Close closes the log file.

func (*FileLogger) Debug

func (l *FileLogger) Debug(msg string, args ...any)

Debug logs a debug message.

func (*FileLogger) Error

func (l *FileLogger) Error(msg string, args ...any)

Error logs an error message.

func (*FileLogger) Info

func (l *FileLogger) Info(msg string, args ...any)

Info logs an info message.

func (*FileLogger) Trace

func (l *FileLogger) Trace(op string, durationMicros int64, success bool, err error, attrs ...slog.Attr)

Trace logs a structured operation trace at DEBUG level. This is optimized to minimize allocations by using slog's native attribute handling.

func (*FileLogger) Warn

func (l *FileLogger) Warn(msg string, args ...any)

Warn logs a warning message.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	Trace(op string, durationMicros int64, success bool, err error, attrs ...slog.Attr)
	Close() error
}

Logger handles persistent file logging for debugging.

func NewFileLoggerOrNull

func NewFileLoggerOrNull(logFilePath string) Logger

NewFileLoggerOrNull creates a FileLogger, falling back to NullLogger on error. This is useful for contexts where logging is optional (e.g., crash handlers).

type NullLogger

type NullLogger struct{}

NullLogger discards all log messages.

func NewNullLogger

func NewNullLogger() *NullLogger

NewNullLogger creates a logger that discards all output.

func (*NullLogger) Close

func (l *NullLogger) Close() error

Close does nothing and returns nil.

func (*NullLogger) Debug

func (l *NullLogger) Debug(_ string, _ ...any)

Debug discards the message.

func (*NullLogger) Error

func (l *NullLogger) Error(_ string, _ ...any)

Error discards the message.

func (*NullLogger) Info

func (l *NullLogger) Info(_ string, _ ...any)

Info discards the message.

func (*NullLogger) Trace

func (l *NullLogger) Trace(_ string, _ int64, _ bool, _ error, _ ...slog.Attr)

Trace discards the trace.

func (*NullLogger) Warn

func (l *NullLogger) Warn(_ string, _ ...any)

Warn discards the message.

type NullOutput

type NullOutput struct{}

NullOutput discards all output (for quiet tests).

func NewNullOutput

func NewNullOutput() *NullOutput

NewNullOutput creates an output that discards everything.

func (*NullOutput) Debug

func (n *NullOutput) Debug(_ string, _ ...any)

Debug discards the message.

func (*NullOutput) DirectiveCD

func (n *NullOutput) DirectiveCD(_ string)

DirectiveCD discards the directive.

func (*NullOutput) DirectiveRerun

func (n *NullOutput) DirectiveRerun(_ ...string)

DirectiveRerun discards the directive.

func (*NullOutput) Error

func (n *NullOutput) Error(_ string, _ ...any)

Error discards the message.

func (*NullOutput) Info

func (n *NullOutput) Info(_ string, _ ...any)

Info discards the message.

func (*NullOutput) IsQuiet

func (n *NullOutput) IsQuiet() bool

IsQuiet always returns true.

func (*NullOutput) Newline

func (n *NullOutput) Newline()

Newline does nothing.

func (*NullOutput) Print

func (n *NullOutput) Print(_ string)

Print discards the content.

func (*NullOutput) Println

func (n *NullOutput) Println(_ string)

Println discards the content.

func (*NullOutput) SetQuiet

func (n *NullOutput) SetQuiet(_ bool)

SetQuiet does nothing.

func (*NullOutput) Success

func (n *NullOutput) Success(_ string, _ ...any)

Success discards the message.

func (*NullOutput) Tip

func (n *NullOutput) Tip(_ string, _ ...any)

Tip discards the message.

func (*NullOutput) Warn

func (n *NullOutput) Warn(_ string, _ ...any)

Warn discards the message.

type Output

type Output interface {
	// Leveled messages with prefixes
	Info(format string, args ...any)
	Warn(format string, args ...any)
	Error(format string, args ...any)
	Tip(format string, args ...any)
	Success(format string, args ...any)
	Debug(format string, args ...any) // Only shown with debug flag

	// Raw output (no formatting)
	Print(content string)
	Println(content string)
	Newline()

	// Shell integration directives (always output, parsed by shell wrapper)
	DirectiveCD(path string)       // Output __STACKIT_CD__:<path> for shell integration
	DirectiveRerun(args ...string) // Output __STACKIT_RERUN__[:args] to run command after cd

	// Quiet mode for TUI coordination
	SetQuiet(quiet bool)
	IsQuiet() bool
}

Output handles user-facing console messages.

type TestOutput

type TestOutput struct {
	*ConsoleOutput
	// contains filtered or unexported fields
}

TestOutput captures output for testing assertions.

func NewTestOutput

func NewTestOutput() *TestOutput

NewTestOutput creates an output that captures all messages for testing.

func (*TestOutput) Bytes

func (t *TestOutput) Bytes() []byte

Bytes returns all captured output as bytes.

func (*TestOutput) Reset

func (t *TestOutput) Reset()

Reset clears the captured output.

func (*TestOutput) String

func (t *TestOutput) String() string

String returns all captured output as a string.

Jump to

Keyboard shortcuts

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