Closed Tenchi2xh closed 6 years ago
Here's what can be achieved with this new feature:
(Here's with the default configuration for comparison)
It's a variant based on the Tomorrow theme available in multiple IDEs
Thanks a lot! This is a very neat and useful contribution, and I wouldn't be able to tell from the code that this was a first-time Haskell contribution :-)
I will try to give some detailed feedback so we can work from there and get this merged into the next release.
The main thing I would like to avoid is building the big list of colours at all. I think this can be done in the following way, by making a mental distinction between "names" and "strings" (even though they're just strings in the end...)
We rename nameForSGR
to sgrToString
and support RGB there
We sgrsByName
to namedSgrs
and don't support RGB here, it's just a table of named ones
We add a new function, stringToSgr :: String -> Maybe Ansi.SGR
which does the following:
rgb
or onRgb
, we do the RGB conversion/parsingnamedSgrs
table, we look it up thereNothing
The FromJSON
style instance can now call stringToSgr
.
This also makes it possible to support rgb#123456
colours later on.
Does this makes sense? Do you agree with this approach? Please let me know if you want to discuss this further. Thanks again for the PR!
Hey that worked! Nice suggestions, I implemented it almost as you described (And thanks for the kind words!)
I'm always surprised when it compiles and then works haha.
I will post an updated 24-bit Tomorrow theme later on π I'm thinking that maybe it would be nice to provide a folder like this in the root of the repo:
.
βββ themes/
Β Β βββ monokai.patat.yaml
Β Β βββ solarized-light.patat.yaml
Β Β βββ solarized-dark.patat.yaml
Β Β βββ tomorrow.patat.yaml
Thanks, the code looks great now!
Hi! Love your project, great upgrade from
mdp
πI added RGB support colors for themes, as supported by
System.Console.ANSI
.The format used in the configuration YAML is the following:
This renders as follows:
The colors are triplets of bytes, mapping
#RGB
to0xRRGGBB
, making for a total of 4096 different colors. Having this short format is enough for the purposes of text, is shorter to write, and also avoids a memory hog / freeze when openingpatat
: sincesgrsByName
contains all different SGR modes including the RGB ones, using the full space of#RrGgBb
would generate 16 million entries (I tried, and it just freezes while loading for a very long time).4096 colors is still quite a lot, so in order to avoid filling the screen with all of them for the error message, I filtered them out and added an explanation:
I'm very far from being fluent in Haskell, so please point out anything that could be written better! This is actually my first Haskell open-source contribution. It's a simple feature but I spent many hours in
ghci
and reading the docs / source code ofSystem.Console.ANSI
andData.Colour
π