You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libdoc: Support setting dark or light mode explicitly #4497
The HTML documentation generated by libdoc can be opened in an IDE, where many people use a dark theme. The contrast between the Robot Framework code on a dark background and the library documentation with a white background is unpleasant.
This problem can be solved if libdoc has a stylesheet parameter to specify the CSS file that should be used to style the documentation. And maybe libdoc should include a light and a dark stylesheet.
This is a good idea and injecting a custom style sheet wouldn't be too complicated. The problem is that we are planning to totally reimplement Libdoc's HTML output (#4304) and that would break all such external style sheets. A related issues that if we allow injecting styles, the whole HTML structure becomes part of the public API and we cannot change it without possibly breaking external styles. At this point it's probably best to wait until we get started with #4304 until we make a decision about that. I'll add a comment about this to that issue. Until this is resolved, you can pretty easily inject styles to the generated HTML file.
Support for dark and light modes is a different thing because it could be just enabled externally and how it actually works would be an implementation detail. More importantly, I think Libdoc already supports the dark mode but I don't know how it's actually activated nor that is there a way to do that programmatically. Ping @Snooz82!
You are right. libdoc.css already supports dark mode, but only if configured in the OS. I think adding a button to manually toggle the dark mode would be a good idea.
@Snooz82, in Vscode and in most new apps meanwhile you can use the system settings or set your own mode. Then the system would be e.g. Dark and the app Light. In Vscode you can even define default themes for the respective system theme.
An advanced idea, In Vscode there are predefined CSS constants for the color scheme that is in use and you can use these in your own sheets. Maybe it would be possible to change the CSS stylesheet of the libdoc via API?
As I commented above, we cannot really make CSS itself configurable until #4304 has been implemented. We'd most likely break all external styles at that point anyway. Even after that defining what parts of the HTML structure are considered public/stable can be tricky.
A toggle to switch between the already supported dark and light modes would be fine because such a toggle can be preserved in the rewrite. I don't see a problem with a visible toggle and believe it would bring some benefits. I doubt it's common knowledge where in the browser to enable the dark mode and having a toggle would also make it explicit that a dark mode exists. The hover text could mention that the default is set by the browser and then users could figure out where to change that. I don't know how hard this would be to implement and since this is UI code also styles need to be thought a bit. If someone is interested to implement such a toggle, it would be great to have a PR latest on Monday when I plan to release RF 6.0 rc 2.
Although a toggle for humans would be nice, I agree with @d-biehl that an API would be nicer as it would allow editor plugins to control the mode. An API would probably be easier to design than a visible toggle as well, so getting this into RF 6.0 ought be pretty easy. Are you @d-biehl interested to provide a PR?
Would it be enough to add new --theme option to Libdoc with possible values DARK, LIGHT and NONE? DARK and LIGHT would force dark and light modes, respectively, and NONE as well as not using the option at all would mean using the default theme.
This would be pretty easy to implement, I have a prototype ready, and ought to give external tools full control on the theme. Theme changes ought to be so rare that needing to regenerate HTML outputs, or serving outputs with previous theme, shouldn't be an issue. This wouldn't allow users changing the theme directly, but I don't consider that too important. Those interested in this can set OS or browser theme as nowadays. A toggle could also be added later if needed.
The HTML documentation generated by libdoc can be opened in an IDE, where many people use a dark theme. The contrast between the Robot Framework code on a dark background and the library documentation with a white background is unpleasant.
Based on that my understanding is that the browser embedded to an IDE uses browser theme, not IDE theme, and it would be convenient to be override that. See also robotcodedev/robotcode#88 references above.
I got --theme option implemented using ideas from this SO answer. Below are changes to HTML and CSS files. Changes to Python files are pretty trivial.
If the changes look fine, and we agree this is a good idea, I can add some tests for the Python side and commit this. We can also agree to not do this now or decide this isn't a good idea in general and just close this issue. I guess @d-biehl and @fabioz as IDE developers have best opinion is this useful or not.
Updated the code above so that setTheme can be called with a theme and it uses getTheme if a theme isn't given. That makes programmatically changing the team possible.
I enhanced the Javascript code for setting the theme a bit (see comment above), added tests and wrote documentation. Now the question is, is this a useful addition, does --theme work in the intended IDE usage, and are the HTML/CSS changes fine?
Do you @Snooz82 have objections adding this? If not, can you check do the above changes look good? Does this implementation work for you @d-biehl?
I want to finally get RF 6.0 rc 2 out today and need to make a decision about this issue. Nobody has commented this lately, but I in my opinion the original request was valid and my implementation seems to work fine so I guess this can be included. I'm only a little concerned about the CSS stuff because I don't have that much experience from these newish features, based on what I've read, and based on my testing, the changes look good.
I'll commit changes after I have eaten so you still have some time to convince me this isn't a good idea or that the implementation has problems. Fixes are obviously possible after this is in as well, but I won't be that interested to revert the whole feature at that point anymore.
Sorry, for the late response, the CSS code looks good to me. What I cannot imagine at the moment, how you implement the --theme, is it a new commandline parameter for libdoc and is it also available in direct call to LibraryDocumentation class?
Activity
pekkaklarck commentedon Oct 6, 2022
This is a good idea and injecting a custom style sheet wouldn't be too complicated. The problem is that we are planning to totally reimplement Libdoc's HTML output (#4304) and that would break all such external style sheets. A related issues that if we allow injecting styles, the whole HTML structure becomes part of the public API and we cannot change it without possibly breaking external styles. At this point it's probably best to wait until we get started with #4304 until we make a decision about that. I'll add a comment about this to that issue. Until this is resolved, you can pretty easily inject styles to the generated HTML file.
Support for dark and light modes is a different thing because it could be just enabled externally and how it actually works would be an implementation detail. More importantly, I think Libdoc already supports the dark mode but I don't know how it's actually activated nor that is there a way to do that programmatically. Ping @Snooz82!
mardukbp commentedon Oct 7, 2022
You are right. libdoc.css already supports dark mode, but only if configured in the OS. I think adding a button to manually toggle the dark mode would be a good idea.
pekkaklarck commentedon Oct 7, 2022
Adding a button sounds good to me. Are you interested to provide a PR?
For IDE interaction there probably should be an API to switch between modes as well. Do @d-biehl or @fabioz have opinions about this?
If enhancements are added fast, they can still make it to RF 6.0. We need another release candidate and my current plan is to release it next Monday.
Snooz82 commentedon Oct 7, 2022
It is not the os defining the color scheme.
It is the browser. But by default the browser takes it from os.
not sure if a switch makes sense. Your browser has a switch for that already.
d-biehl commentedon Oct 7, 2022
I like the idea. And an API would be even better.
@Snooz82, in Vscode and in most new apps meanwhile you can use the system settings or set your own mode. Then the system would be e.g. Dark and the app Light. In Vscode you can even define default themes for the respective system theme.
An advanced idea, In Vscode there are predefined CSS constants for the color scheme that is in use and you can use these in your own sheets. Maybe it would be possible to change the CSS stylesheet of the libdoc via API?
pekkaklarck commentedon Oct 8, 2022
As I commented above, we cannot really make CSS itself configurable until #4304 has been implemented. We'd most likely break all external styles at that point anyway. Even after that defining what parts of the HTML structure are considered public/stable can be tricky.
A toggle to switch between the already supported dark and light modes would be fine because such a toggle can be preserved in the rewrite. I don't see a problem with a visible toggle and believe it would bring some benefits. I doubt it's common knowledge where in the browser to enable the dark mode and having a toggle would also make it explicit that a dark mode exists. The hover text could mention that the default is set by the browser and then users could figure out where to change that. I don't know how hard this would be to implement and since this is UI code also styles need to be thought a bit. If someone is interested to implement such a toggle, it would be great to have a PR latest on Monday when I plan to release RF 6.0 rc 2.
Although a toggle for humans would be nice, I agree with @d-biehl that an API would be nicer as it would allow editor plugins to control the mode. An API would probably be easier to design than a visible toggle as well, so getting this into RF 6.0 ought be pretty easy. Are you @d-biehl interested to provide a PR?
d-biehl commentedon Oct 9, 2022
Let me finish the other PR first. And then I'll take a look at it. But I don't think I'll make it until Monday. Tuesday or Wednesday more likely.
pekkaklarck commentedon Oct 10, 2022
Would it be enough to add new
--themeoption to Libdoc with possible values DARK, LIGHT and NONE? DARK and LIGHT would force dark and light modes, respectively, and NONE as well as not using the option at all would mean using the default theme.This would be pretty easy to implement, I have a prototype ready, and ought to give external tools full control on the theme. Theme changes ought to be so rare that needing to regenerate HTML outputs, or serving outputs with previous theme, shouldn't be an issue. This wouldn't allow users changing the theme directly, but I don't consider that too important. Those interested in this can set OS or browser theme as nowadays. A toggle could also be added later if needed.
Snooz82 commentedon Oct 10, 2022
I do not get it!
the page shows the content theme based on the setting of the browser.
Why forcing anything?
pekkaklarck commentedon Oct 10, 2022
The original description has this:
Based on that my understanding is that the browser embedded to an IDE uses browser theme, not IDE theme, and it would be convenient to be override that. See also robotcodedev/robotcode#88 references above.
pekkaklarck commentedon Oct 10, 2022
I got
--themeoption implemented using ideas from this SO answer. Below are changes to HTML and CSS files. Changes to Python files are pretty trivial.If the changes look fine, and we agree this is a good idea, I can add some tests for the Python side and commit this. We can also agree to not do this now or decide this isn't a good idea in general and just close this issue. I guess @d-biehl and @fabioz as IDE developers have best opinion is this useful or not.
Updated the code above so that
setThemecan be called with a theme and it usesgetThemeif a theme isn't given. That makes programmatically changing the team possible.pekkaklarck commentedon Oct 10, 2022
I enhanced the Javascript code for setting the theme a bit (see comment above), added tests and wrote documentation. Now the question is, is this a useful addition, does
--themework in the intended IDE usage, and are the HTML/CSS changes fine?Do you @Snooz82 have objections adding this? If not, can you check do the above changes look good? Does this implementation work for you @d-biehl?
[-][ENHANCEMENT] Add a stylesheet parameter to libdoc[/-][+]Libdoc: Support setting dark or light mode explicitly[/+]pekkaklarck commentedon Oct 11, 2022
I want to finally get RF 6.0 rc 2 out today and need to make a decision about this issue. Nobody has commented this lately, but I in my opinion the original request was valid and my implementation seems to work fine so I guess this can be included. I'm only a little concerned about the CSS stuff because I don't have that much experience from these newish features, based on what I've read, and based on my testing, the changes look good.
I'll commit changes after I have eaten so you still have some time to convince me this isn't a good idea or that the implementation has problems. Fixes are obviously possible after this is in as well, but I won't be that interested to revert the whole feature at that point anymore.
d-biehl commentedon Oct 11, 2022
Sorry, for the late response, the CSS code looks good to me. What I cannot imagine at the moment, how you implement the --theme, is it a new commandline parameter for libdoc and is it also available in direct call to LibraryDocumentation class?
pekkaklarck commentedon Oct 11, 2022
It's a command line option and various APIs also got
theme=Noneargument. For example, this usage works:If you have access to the browser JS environment, calling
setTheme('dark')works as well. I'll commit changes so you can see and test yourself.Libdoc: Support setting dark/light theme explicitly. #4497
pekkaklarck commentedon Oct 11, 2022
This ought to be done now but I keep this open for a little time to see if there's some more feedback.