-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor(colors): Rework colors
structure
#13
base: main
Are you sure you want to change the base?
Conversation
- Add support for ANSI 4-bit colors - Fix `-dec` computation
Good evening, thank you for your PR. I have a few questions:
|
A
WezTerm was my motivation, since I use it; another example is Alacritty which wouldn't even need programs.alacritty.settings.colors = let inherit (builtins) removeAttrs; in {
normal = removeAttrs scheme.withHashtag.ansi.dark ["toList"];
bright = removeAttrs scheme.withHashtag.ansi.bright ["toList"];
}; (to be honest, I only found out how that is configured while writing this comment; with that in mind, renaming Actually, anywhere you see a terminal you would want to use
You might've noticed that I updated the doc comment for
I made a
There are two theoretically breaking changes:
|
The changes make sense, I've added some small comments. Maybe you can replace the point-free style with plain lambdas? I'm not that familiar with the nixpkgs library and sometimes the overhaul of compositions looks unnecessary complex |
I can agree that sometimes the point-freeness is too extreme, will change. |
Hi, I've left a couple of comments |
total = palette: based palette // extra palette; | ||
total' = | ||
palette: | ||
mapRecursiveCond (x: lib.strings.isConvertibleWithToString x -> isList x) toString (total palette) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain what does this line do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all it takes total palette
; after that it transforms recursively:
- If the value under question is not
toString
-able or is a list, recurse withmapAttrs
ormap
- Otherwise use
toString
to turn it into a string
Effectively this transforms all color nodes into strings (they have a __toString
attr so they are toString
-able) while keeping the attrset (e.g. mnemonic
, ansi
, ansi.bright
) and list (e.g. ansi.dark.toList
) structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a workaround. I think you can remove both __toString
and instead use a common attribute like .asString
. Then it will look like mapRecursiveCond (x: x ? asString) (x: x.asString) (total palette)
.
As far as I understood, you use the implicit conversion to string in only in one other place - in the code for the _color
function. There you can do without this conversion: instead of self.hex
just use the hex
parameter. This will also make for a simpler control flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My previous comment was incomplete: this transformation also affects numbers such as base01-dec-r
and base0E-rgb-b
, so lib.strings.isConvertibleWithToString x -> isList x
is not really simplifiable (an alternative is isFloat x || isInt x || (isAttrs x && x ? hex)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe we can convert them to string in the _color function itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but in your PR they still get converted to string, don't they? We can explicitly convert them to string as I proposed above, and provide additional attributes with the integer values. @thecaralice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, they are converted to strings to match base16/24 spec, and they have the additional attributes in the original
attrset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I got it. After another thought, the actual problem is the following. You open too much of the internals of the library (increasing the future maintenance burden) to save a little time for 1% of "power users".
But even further, even this potential time saving is under question. Right now, the features you've added are undocumented, so nobody will know about them, thus they are code bloat. Even if we add documentation, it would look like "remember that dec-r attribute? We called lib.strings.toInt
for you and you can access this value via original.base00.dec-r
", being another sort of bloat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, as I've stated in the README, the primary purpose of base16.nix is to be an interface to the base16 standard. Any additional features I want to keep at minimum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, can you please document the featuers you've added in the DOCUMENTATION.md?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one more comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, added a couple of comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, left one comment.
PS sorry for the wait, I was on a trip.
total = palette: based palette // extra palette; | ||
total' = | ||
palette: | ||
mapRecursiveCond (x: lib.strings.isConvertibleWithToString x -> isList x) toString (total palette) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused. By scripting do you mean user-level scripting? Because you still convert them to string, so for the user it does not matter.
-dec
computation