Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v2) feat: add WithRequestBackground option to query terminal background c… #1211

Open
wants to merge 2 commits into
base: v2-exp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 options.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,14 @@ func WithGraphemeClustering() ProgramOption {
p.startupOptions |= withGraphemeClustering
}
}

// 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
}
}
4 changes: 4 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const (
withReportFocus
withKeyboardEnhancements
withGraphemeClustering
withRequestBackgroundColor
)

// channelHandlers manages the series of channels returned by various processes.
Expand Down Expand Up @@ -768,6 +769,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()
Expand Down
Loading