stylix icon indicating copy to clipboard operation
stylix copied to clipboard

rstudio: init

Open Mrbroggle opened this issue 9 months ago • 20 comments

created a module for rStudio. File is really because because all 256 terminal colours need to be maually assigned. If anyone can think of better way to do this please fix it :)

Mrbroggle avatar Mar 03 '25 07:03 Mrbroggle

Since our colorscheme currently only provides 16 colors, the 256 colors need to converge to them. Depending on the intended behaviour, the mapping from 256 to 16 can be partially generated.

Btw, the formatting CI is failing.

I don't think thats what should be done, RStudio makes you manually define each colour for the in-built terminal, so these were squashed from 256 into 16 colour you would lose 256 colour support for RStudio. I can do this if you think its right for the project however.

Mrbroggle avatar Mar 17 '25 22:03 Mrbroggle

I was going to write a whole long winded explantion of how if i wrote this module without hacky work arounds and permission changing it wouldn't work, in the process i changed my module to be more in line with the stylix ideals and now it works mostly fine.

Without the 256 colour support, the internal terminal doesnt work looking something like this image

Mrbroggle avatar Mar 19 '25 22:03 Mrbroggle

Does this mean this part can be removed? If we also enable the module by default, we could entirely remove this README.md file.

I think we should enable it by default if either the rStudio package or rStudioWrapper is installed, but im not sure how to do that so any pointers would be nice. Happy to change that

Mrbroggle avatar Mar 24 '25 14:03 Mrbroggle

Does this mean this part can be removed? If we also enable the module by default, we could entirely remove this README.md file.

I think we should enable it by default if either the rStudio package or rStudioWrapper is installed, but im not sure how to do that so any pointers would be nice. Happy to change that

Usually, unless we are dealing with external applications we just enable modules by default, except if there are known problems in certain environments. For reference, here is how the NixVim module is only enabled if it has been detected:

https://github.com/danth/stylix/blob/d9df91c55643a8b5229a3ae3a496a30f14965457/modules/nixvim/nixvim.nix#L136-L140

trueNAHO avatar Mar 24 '25 14:03 trueNAHO

Does this mean this part can be removed? If we also enable the module by default, we could entirely remove this README.md file.

I think we should enable it by default if either the rStudio package or rStudioWrapper is installed, but im not sure how to do that so any pointers would be nice. Happy to change that

Usually, unless we are dealing with external applications we just enable modules by default, except if there are known problems in certain environments. For reference, here is how the NixVim module is only enabled if it has been detected:

https://github.com/danth/stylix/blob/d9df91c55643a8b5229a3ae3a496a30f14965457/modules/nixvim/nixvim.nix#L136-L140

All changes sugested have been pushed. The module is now enabled by default.

Mrbroggle avatar Mar 24 '25 14:03 Mrbroggle

you should add a testbed

I added this. For some reason the application doesn't autostart or show in the menu, but it can be launched from the console.

danth avatar Mar 31 '25 10:03 danth

@trueNAHO please can you check whether the conversations from your previous review should be resolved :))

danth avatar Mar 31 '25 21:03 danth

@trueNAHO please can you check whether the conversations from your previous review should be resolved :))

@Mrbroggle, the dark and light themes look the same when starting the application in the testbeds:

Is it possible for the application to be themed dark depending on the theme? Maybe based on the polarity?

I ran the testbeds and selected theme in rstudio and it themes correctly nix run .#testbed:rstudio:default:dark:image:scheme:cursor image

nix run .#testbed:rstudio:default:light:image:scheme:cursorless image

Did you apply the theme in settings under Tools > Global Options > Appearence > Editor Theme ? There is a file under ~/.confg/rstudio/rstudio-prefs.json that stores the editor theme but that would require changing only one line in the file and im not sure how one might do that because that file stores all the other settings for RStudio and needs RW perms which i think is out the scope of stylix?

example of my rstudio-prefs.json:

{
    "initial_working_directory": "~/Projects/uni/R",
    "pdf_previewer": "none",
    "posix_terminal_shell": "custom",
    "terminal_bell_style": "none",
    "highlight_r_function_calls": true,
    "editor_theme": "stylixBase16",
    "custom_shell_command": "/run/current-system/sw/bin/fish",
    "default_open_project_location": "~/Projects/uni/R",
    "relative_line_numbers": true,
    "show_diagnostics_other": true,
    "editor_keybindings": "vim",
    "text_rendering": "geometricPrecision",
    "show_rmd_render_command": true,
    "rmd_viewer_type": "pane",
    "disable_renderer_accessibility": true,
    "graphics_backend": "cairo",
    "soft_wrap_r_files": true
}

Mrbroggle avatar Apr 01 '25 08:04 Mrbroggle

Is it possible for the application to be themed dark depending on the theme? Maybe based on the polarity?

[...]

Did you apply the theme in settings under Tools > Global Options > Appearence > Editor Theme ? There is a file under ~/.confg/rstudio/rstudio-prefs.json that stores the editor theme but that would require changing only one line in the file and im not sure how one might do that because that file stores all the other settings for RStudio and needs RW perms which i think is out the scope of stylix?

@danth, should we use a home.activation script?

trueNAHO avatar Apr 01 '25 09:04 trueNAHO

@danth, should we use a home.activation script?

we could use jq in home.activation script something like

mv rstudio-prefs.json temp.json
jq -r '.editor_theme|= "stylixBase16"' temp.json > rstudio-prefs.json
rm temp.json

Mrbroggle avatar Apr 01 '25 09:04 Mrbroggle

Yes, that seems reasonable. We could use sponge to avoid creating a temporary file.

We'd also have to handle the case where the file hasn't been initialised yet.

danth avatar Apr 01 '25 10:04 danth

A simple jq with checking if the file already exists might be simpler.

trueNAHO avatar Apr 01 '25 11:04 trueNAHO

all seems to be working now and auto setting the theme. It is installing jq and spone however. Which I though in the way implementend should be temporary just for this script? Anyway, let me know if any other changes need to be made.

Mrbroggle avatar Apr 06 '25 02:04 Mrbroggle

@Mrbroggle, can you approve commit c680a63 ("rstudio: polish Bash code") and 545f5e3 ("rstudio: add required meta.name attribute")?

changes should be applied.

Mrbroggle avatar Apr 10 '25 09:04 Mrbroggle

Can confirm, this is now working.

However, some of the text is difficult to read with a light theme:

Screenshot of file browser

I couldn't find which part of the template is causing this.

danth avatar Apr 13 '25 11:04 danth

I couldn't find which part of the template is causing this. I did a test, this issue is here in the mustache file:

/* rs-theme-is-dark: TRUE */

Im not sure how to do this programatically but we'd need to change this with the polarity.

Mrbroggle avatar Apr 13 '25 22:04 Mrbroggle

I fixed it in a pretty scuffed way, i wasnt too sure how else to do it other than concat the header with the template but its working.

Mrbroggle avatar Apr 17 '25 14:04 Mrbroggle

Im not sure how to do this programatically but we'd need to change this with the polarity.

All of the colors should be coming directly from the theme; the polarity option is only to control the automatically generated default theme and may not be correct otherwise. Its default is either.

If the RStudio theme absolutely must specify whether it is light or dark, this should be done by testing the actual colors in the theme rather than using the polarity value.

danth avatar Apr 27 '25 16:04 danth

If the RStudio theme absolutely must specify whether it is light or dark, this should be done by testing the actual colors in the theme rather than using the polarity value.

To fix the difficulty to read part here

However, some of the text is difficult to read with a light theme:

Screenshot of file browser

we must set the /* rs-theme-is-dark: */ to either true or false so it must be set.

Ive used the rgb values from base00 and calculated luminosity to set the theme-is-dark. I think this should be good.

Mrbroggle avatar Apr 28 '25 12:04 Mrbroggle

Not sure why this CI/CD is failing, something to do with a failed build of jypter and gyp not being installed, testbed runs on my local machine though.

Mrbroggle avatar May 10 '25 08:05 Mrbroggle