-
Notifications
You must be signed in to change notification settings - Fork 79
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
Lipgloss doesn't detect background correctly when using wish #262
Comments
Also running into this! Happy to help if there's any opportunity to do so. |
A pty is not in foreground, but it can do the IOCTL ops we need. My understanding might be wrong, but I think that if the term cannot do the TCGETS it will fail the same way it would when checking if its in foreground, so maybe that check is even needed? refs charmbracelet/wish#262
FWIW we're looking into it :) thanks for the detailed report |
Awesome, thank you! |
use our new term lib to query the bg, set it into the lipgloss renderer so it works with everything. refs #262
use our new term lib to query the bg, set it into the lipgloss renderer so it works with everything. refs #262
can you try on main? |
Sure! I've tried to run the example i provided in the gist with the main branch of wish, however the issue still persists. I've executed
And i am now on version Perhaps there is something else i'm missing? |
afaik that should be it, can you share the project you're working on? |
Of course! I've pushed my test project here: https://github.com/Aerochrome/charm-bg-test |
right now it'll only work if you use allocatepty, I'm afraid still looking into it though |
I can confirm that on wish Thanks! |
awesome, thank you! |
Describe the bug
When using the
bubbletea.MakeRenderer
function,lipgloss.AdaptiveColor
andlipgloss.Renderer.HasDarkBackground
always assume a black background, even though the terminal emulator from which i am using ssh has set a light background.Setup
I'm running the wish example locally with
go run .
and also use a local terminal to access the ssh server.It happens on Fedora 40 and MacOS with Gnome Terminal, iTerm2 and the standard mac terminal (all using zsh).
To Reproduce
log.Info(renderer.HasDarkBackground())
in theteaHandler
function right after creating the renderer using the bubbletea middlewareteaHandler
function that uses the renderer created using the bubbletea middleware andlipgloss.AdaptiveColor
3.1 Render some text in the
View()
method of the model using the adaptive color lipgloss styleSource Code
I've created a simple one-file example in this gist:
https://gist.github.com/Aerochrome/5fd2af09f94eda22a0875068b8824acc
Expected behavior
When accessing with a terminal emulator with a light background, the second line should be colored pink.
When accessing with a dark background, the second line should be colored red.
Screenshots
Expectation:
Reality:
Additional context
DISCLAIMER: I am very new to TUIs and fairly new to go, so i'm not sure how useful my debugging findings actually are, but i want to share them nonetheless in case they're of any use.
I suspect that this issue might be related to a missing
Fd()
method implementation on thessh.Session
struct.In the
bubbletea.newRenderer
method in this file a check is performed on whether the Slave pointer is nil. If so, it passes the session struct intolipgloss.NewRenderer
.While this struct has a
Write
method, it doesn't seem to implement theFd
method.When adding a very rudimentary one like so, the background color check seems to work properly and produces a working example.
Of course, this doesn't account for
sess.pty.Slave
being nil (even though it produces a working example even if it is nil and i'm unsure why).This suspicion is further confirmed by looking at an older wish example in the lipgloss repository, where a "helper" struct is created to pass into
lipgloss.Renderer.SetOutput
which also implementsWrite
andFd
.It also implements
Read
, though it doesn't seem to influence the outcome of a working example in my case.So i've tried to use this helper struct, setting tty to pty.Slave and passing it into
bubbletea.MakeRenderer
like so, which produces a working example.Again, this also works if
pty.Slave
is nil.It is also worth mentioning that in my case checking pty.Master and pty.Slave against nil in the
teaHandler
function returns true in both cases, even thoughs.Pty()
returns true as third return value which i assume means that a PTY was accepted for this session.I don't know if this is expected behavior in this specific case?
The text was updated successfully, but these errors were encountered: