From 8081d07867b5f884af2c87a9113481c12b7d4203 Mon Sep 17 00:00:00 2001 From: Zachary Schneider Date: Fri, 4 Dec 2026 10:17:18 -0500 Subject: [PATCH] feat(cli): suppress the banner when PEL_NO_BANNER is set --- internal/cli/banner/banner.go | 11 +++++++++++ internal/cli/banner/banner_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/internal/cli/banner/banner.go b/internal/cli/banner/banner.go index 68527fb95..e51475e26 100644 --- a/internal/cli/banner/banner.go +++ b/internal/cli/banner/banner.go @@ -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 ( @@ -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. @@ -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 { diff --git a/internal/cli/banner/banner_test.go b/internal/cli/banner/banner_test.go index e3dbae63e..d77add672 100644 --- a/internal/cli/banner/banner_test.go +++ b/internal/cli/banner/banner_test.go @@ -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