superfile: init - #2398
Conversation
|
Well, tbh, I dunno what's going on with Any help here would be much appreciated 🙇 |
| code_syntax_highlight = lib.mkOption { | ||
| description = "The syntax highlighting theme for code."; | ||
| type = lib.types.str; | ||
| }; |
There was a problem hiding this comment.
A mandatory
stylix.targets.superfile.code_syntax_highlightoption is introduced for the syntax highlighting theme in file previews, since there is no automatic way to map a base16 colorscheme to a valid chroma syntax style. Users must set this to a chroma-compatible style name (e.g."catppuccin-macchiato").
What about adapting and applying the upstream Tokyonight style to remove this option:
The implementation takes the built-in tokyonight theme from superfile's source as a reference for the color mappings.
There was a problem hiding this comment.
@trueNAHO The point is that this option should be customizable, because chroma has several colorschemes, and from my POV (feel free to just say "shut-up, you have no idea what you're talking about") one should be able to choose it. Here is the list: https://github.com/alecthomas/chroma/blob/master/styles
There was a problem hiding this comment.
The point is that this option should be customizable, because
chromahas several colorschemes, and from my POV (feel free to just say "shut-up, you have no idea what you're talking about") one should be able to choose it. Here is the list: https://github.com/alecthomas/chroma/blob/master/styles
End-users can override this option with lib.mkForce.
IMHO, declaring an appropriate syntax highlighter should be handled by Stylix. I was hoping it would be possible to inject our own style, which could be derived from catppuccin-macchiato.
There was a problem hiding this comment.
@trueNAHO Unfortunately we can't set the highlight colors through Stylix (it would be the dream).
As you can see here: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/ui/preview/render.go#L131, it calls ansichroma passing the value from the variable code_syntax_highlight: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/common/config_type.go#L6C2-L6C26
But I agree with the usage of lib.mkForce. A good middle ground here could be applying a more neutral default value, could be catppuccin or tokyonight (or any other from the chroma available styles) and allow users to overwrite with lib.mkForce. Wdyt?
In that case, do you have any suggestions in term of a theme that could blend "kinda well" with any theme? If not, I'll follow with tokyonight. It is not a theme of strong colors, looks very neutral to me.
Let me know what you think, I have the commit ready to push.
There was a problem hiding this comment.
Unfortunately we can't set the highlight colors through Stylix (it would be the dream).
As you can see here: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/ui/preview/render.go#L131, it calls ansichroma passing the value from the variable
code_syntax_highlight: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/common/config_type.go#L6C2-L6C26[...] A good middle ground here could be applying a more neutral default value, could be catppuccin or tokyonight (or any other from the chroma available styles) and allow users to overwrite with
lib.mkForce. Wdyt?In that case, do you have any suggestions in term of a theme that could blend "kinda well" with any theme? If not, I'll follow with
tokyonight. It is not a theme of strong colors, looks very neutral to me.
From where is code_syntax_highlight reading the file contents? Ideally, code_syntax_highlight would support an absolute file path. If code_syntax_highlight accesses styles from a runtime directory, our style could be injected by installing it there. If code_syntax_highlight bundles the set of available styles into the static binary, we might consider patching pkgs.superfile to include our style into the build pipeline.
There was a problem hiding this comment.
@trueNAHO Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.
Did a whole research on how Superfile calls ansichroma and how ansichroma itself uses styles from chroma v2.
I've added some details to the PR description and to the commit msg, but a ;tldr;:
chroma has a global Registry variable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch the superfile binary with the XML and found a solution.
I've tested on the testbed and it worked nice, also is running nice on my setup too.
Please, drop any feedbacks and I'll take a look ASAP.
Cheers.
There was a problem hiding this comment.
Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.
[...]
[...]
chromahas a globalRegistryvariable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch thesuperfilebinary with the XML and found a solution.
Despite my limited Go knowledge, there are various potential future problems with the current overlay implementation. However, if your research concludes this is the best solution without major upstream changes, I am fine with this approach.
I've tested on the
testbedand it worked nice, also is running nice on my setup too.
Seems to currently work in the testbed:
Tested-by: Noah Biewesch <dev@noahbiewesch.com>
Refresh the pre-commit cache: rm .pre-commit-config.yaml && nix develop |
|
@trueNAHO Addressed all points except for one: the implementation of |
8d1c707 to
572c318
Compare
|
Also, squashed the commits. |
superfile: use maintainer last name Update modules/superfile/testbeds/superfile.nix Co-authored-by: Noah Biewesch <dev@noahbiewesch.com> superfile: address comments and gen all-maintainers superfile: remove code_syntax_highlight option
Generates a chroma XML syntax style from the Stylix palette at build time via a nixpkgs overlay, and injects it into superfile using go:embed to register at startup. So code highlighting always matches the system theme with no user configuration.
c9ae9c8 to
a88fd41
Compare
|
@ReeSilva the pre-commit checks are failing |
ooh, has been some time hehe 😅 let me take a quick look and get back to you |
|
@0xda157 fixed :) |
|
It looks like something got messed up when merging, as 1c283f2 should not be part of this pr. |
46aeab9 to
bb5f96c
Compare
|
@0xda157 fixed |
0xda157
left a comment
There was a problem hiding this comment.
LLM written PR descriptions are not helpful. If I wanted a LLM summary of your PR I could get a LLM to summarize it myself.
| settings.theme = "stylix"; | ||
| themes.${theme} = { | ||
| code_syntax_highlight = "stylix"; | ||
| full_screen_fg = colors.withHashtag.base05; |
There was a problem hiding this comment.
this would be more readable with with color.withHashtag
| ({ colors, ... }: { | ||
| programs.superfile = | ||
| let | ||
| theme = "stylix"; |
There was a problem hiding this comment.
could you inline this please
There was a problem hiding this comment.
The better fix might be to use the variable to indicate the relation:
- code_syntax_highlight = "stylix";
+ code_syntax_highlight = theme;| { mkTarget, ... }: | ||
| mkTarget { | ||
| config = [ | ||
| ({ colors, ... }: { |
There was a problem hiding this comment.
mkTarget modules should only specify what they require
| ({ colors, ... }: { | |
| ({ colors }: { |
| config = [ | ||
| ({ colors, ... }: { |
There was a problem hiding this comment.
| config = [ | |
| ({ colors, ... }: { | |
| config = { colors, ... }: { |
|
|
||
| chromaXml = pkgs.writeText "stylix-chroma.xml" '' | ||
| <style name="stylix"> | ||
| <entry type="Background" style="bg:#${colors.base00}"/> |
There was a problem hiding this comment.
use with colors.withHashtag here please.
| ({ colors, ... }: { | ||
| programs.superfile = | ||
| let | ||
| theme = "stylix"; |
There was a problem hiding this comment.
The better fix might be to use the variable to indicate the relation:
- code_syntax_highlight = "stylix";
+ code_syntax_highlight = theme;| postPatch = (old.postPatch or "") + '' | ||
| cp ${registerGo} ./register-stylix.go | ||
| cp ${chromaXml} ./stylix-chroma.xml | ||
| ''; |
There was a problem hiding this comment.
Nitpick:
| postPatch = (old.postPatch or "") + '' | |
| cp ${registerGo} ./register-stylix.go | |
| cp ${chromaXml} ./stylix-chroma.xml | |
| ''; | |
| postPatch = '' | |
| ${old.postPatch} | |
| cp ${registerGo} ./register-stylix.go | |
| cp ${chromaXml} ./stylix-chroma.xml | |
| ''; |
| firstUseCheck = false; | ||
| settings = { | ||
| auto_check_update = false; | ||
| ignore_missing_fields = true; |
| enable = true; | ||
| firstUseCheck = false; | ||
| settings = { | ||
| auto_check_update = false; |
| inherit (lib) optionalAttrs; | ||
| inherit (config.lib.stylix) colors; | ||
|
|
||
| chromaXml = pkgs.writeText "stylix-chroma.xml" '' |
There was a problem hiding this comment.
What is the purpose of duplicating the GenericStrong declaration?
| { lib, pkgs, ... }: { | ||
| stylix.testbed.ui = { | ||
| command = { | ||
| text = lib.getExe pkgs.superfile; |
There was a problem hiding this comment.
This should probably open the flake-parts directory inside the testbed.
| if err != nil { | ||
| panic(err) | ||
| } |
There was a problem hiding this comment.
Unless this is the idiomatic Go formatting, the following might be better:
| if err != nil { | |
| panic(err) | |
| } | |
| if err != nil { | |
| panic(err) | |
| } | |
| inherit (lib) optionalAttrs; | ||
| inherit (config.lib.stylix) colors; | ||
|
|
||
| chromaXml = pkgs.writeText "stylix-chroma.xml" '' |
There was a problem hiding this comment.
Unless the declaration order follows the default upstream themes, what about lexicographically sorting them?
| code_syntax_highlight = lib.mkOption { | ||
| description = "The syntax highlighting theme for code."; | ||
| type = lib.types.str; | ||
| }; |
There was a problem hiding this comment.
Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.
[...]
[...]
chromahas a globalRegistryvariable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch thesuperfilebinary with the XML and found a solution.
Despite my limited Go knowledge, there are various potential future problems with the current overlay implementation. However, if your research concludes this is the best solution without major upstream changes, I am fine with this approach.
I've tested on the
testbedand it worked nice, also is running nice on my setup too.
Seems to currently work in the testbed:
Tested-by: Noah Biewesch <dev@noahbiewesch.com>
Closes: #2397
Add a Home Manager target for Superfile, a modern terminal file manager written in Go.
The target maps the entire superfile theme TOML configuration to base16 colors — covering the file panel, sidebar, footer, modals, help menu, and special state colors (cursor, error, correct, hint, cancel).
Syntax highlighting in file previews is handled automatically: a nixpkgs overlay generates a chroma syntax style from the Stylix palette at build time, then injects a small Go file into superfile's source that registers it at startup via
//go:embed, so code highlighting always matches the system theme with no user configuration.The implementation takes the built-in tokyonight theme from superfile's source as a reference for the UI color mappings, and the catppuccin and tokyonight chroma styles as references for the syntax highlighting color mappings.
Also includes a testbed for the target — it disables the first-use check, auto-update, and nerdfonts, and sets
ignore_missing_fields = trueto prevent warnings from the options that superfile requires to work (but are not required to test the appearance).AI Usage Disclosure
This PR description and the code for the automatic syntax highlighting were written with assistance from the AI agent Opencode via CodeCompanion.nvim, using the model DeepSeek V4 Pro through Opencode Zen. The rest of the code was written entirely by me.