Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/cli/banner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const (

// DocRoot is the root URL for online documentation.
DocRoot = "https://docs.formae.io/en/latest"

// NoBannerEnv is the environment variable that suppresses the banner when
// set to any non-empty value.
NoBannerEnv = "PEL_NO_BANNER"
)

var (
Expand Down Expand Up @@ -69,6 +73,9 @@ func ClearScreen() {
// clean. This uses IsTerminal(os.Stdout), NOT IsInteractive, because the banner
// never reads stdin.
//
// The banner is also suppressed when PEL_NO_BANNER is set to a non-empty value,
// for people who want a TTY session without the logo.
//
// For CapText the art is already "formae v{version}" — just print it.
// For braille/graphics, rows is a countRows estimate. Graphics art includes the
// wordmark as plain newline-separated lines below the image — no cursor escapes.
Expand Down Expand Up @@ -96,6 +103,10 @@ func printBanner(allowGraphics bool) {
if !isTerminal(os.Stdout) {
return
}
// Opt-out gate: the user asked for no banner.
if os.Getenv(NoBannerEnv) != "" {
return
}

cap := detect()
if !allowGraphics && cap == logo.CapKitty {
Expand Down
25 changes: 25 additions & 0 deletions internal/cli/banner/banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ func TestPrintBanner_SuppressedNonTTY(t *testing.T) {
assert.False(t, detectCalled, "detect should not be called when suppressed")
}

// TestPrintBanner_SuppressedByEnv verifies that PEL_NO_BANNER suppresses both
// banner variants on a TTY, and that an empty value does not.
func TestPrintBanner_SuppressedByEnv(t *testing.T) {
origIsTerminal := isTerminal
origDetect := detect
t.Cleanup(func() {
isTerminal = origIsTerminal
detect = origDetect
})

isTerminal = func(_ io.Writer) bool { return true }
detect = func() logo.Capability { return logo.CapText }

t.Run("set", func(t *testing.T) {
t.Setenv(NoBannerEnv, "1")
assert.Empty(t, captureStdout(func() { PrintBanner() }))
assert.Empty(t, captureStdout(func() { PrintTextBanner() }))
})

t.Run("empty", func(t *testing.T) {
t.Setenv(NoBannerEnv, "")
assert.NotEmpty(t, captureStdout(func() { PrintBanner() }))
})
}

// TestPrintBanner_LeadingBlankLine verifies that PrintBanner separates the logo
// from the previous shell line with a blank line above it — for both the
// text/braille branch and the graphics branch. Without it the logo renders
Expand Down
Loading