diff --git a/options.go b/options.go index a1db34ad72..16dec464eb 100644 --- a/options.go +++ b/options.go @@ -271,6 +271,17 @@ func WithGraphemeClustering() ProgramOption { } } +// WithRequestBackground starts the program with a request to query the +// background color of the terminal. +// +// This is useful if you want to know the background color of the terminal. The +// background color will be sent to your program as a [BackgroundMsg]. +func WithRequestBackground() ProgramOption { + return func(p *Program) { + p.startupOptions |= withRequestBackgroundColor + } +} + // WithColorProfile sets the color profile that the program will use. This is // useful when you want to force a specific color profile. By default, Bubble // Tea will try to detect the terminal's color profile from environment diff --git a/tea.go b/tea.go index 2a1494ba46..bbecdc40a2 100644 --- a/tea.go +++ b/tea.go @@ -110,6 +110,7 @@ const ( withColorProfile withKeyboardEnhancements withGraphemeClustering + withRequestBackgroundColor ) // channelHandlers manages the series of channels returned by various processes. @@ -791,6 +792,9 @@ func (p *Program) Run() (Model, error) { p.execute(ansi.RequestKittyKeyboard) } } + if p.startupOptions.has(withRequestBackgroundColor) { + p.execute(ansi.RequestBackgroundColor) + } // Start the renderer. p.startRenderer()