Skip to content
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

Additional Theme Features #925

Merged
merged 3 commits into from
Jul 29, 2024
Merged

Additional Theme Features #925

merged 3 commits into from
Jul 29, 2024

Conversation

NotTheDr01ds
Copy link
Contributor

@NotTheDr01ds NotTheDr01ds commented Jul 29, 2024

Changes to make.nu:

  • Adds in missing shapes and types noted further down in this PR by @fdncred
  • Adds colors for types - Mostly matching the corresponding shape, but with any attribute (e.g., bold) removed
  • Changed int and float values to be distinct. In most themes, the colors should be complementary.
  • Changes bool: false and hints colors - They were hardcoded to dark_grey and wouldn't show up on some themes. Now uses a theme color that should correspond to a theme-appropriate grey in most cases.
  • Alphabetizes shapes and types so that Previews are also sorted properly
  • Eliminated spurious newline when sourcing theme (from printing OSC codes for terminal colors)
  • Renamed 3024 theme to 3024r since module names can't be an int

Changes to theme preview small:

  • Remove extra vertical spacing that was caused by different-sized row column content
  • Logically group elements - Types, Conditionally computed (closures) types, Shapes, and other Structure (e.g., header, row_index, foreground, etc.)
  • Displays foreground/background on one line for clarity

Result is a much more compact, but also more readable, table.

Comparison:

Before

After

  • Also refactored a lot of the code to be more maintainable - Moves the rendering off to separate functions.

Changes to preview_generate_screenshots.nu:

  • Accepts the method for generating screenshots as an argument
  • Additional generation method using asciinema, agg (asciinema to animated gif), and ffmpeg (to convert the animated gif to a single-image PNG)

Additional Notes:

  • Some Lemnos themes use color values that are the same (or nearly the same) as the background in places. These are "broken" themes and always have been as some elements will simply not be visible.

  • There's a longstanding (I believe) bug that special-cased record for the key rather than the value. I've fixed it so that the key is now handled properly (same as other types), but I haven't implemented any changes for color values that use a record (e.g., { fg: "#80a1a1", attr: "b" }) as this would make the table less compact. I'll look at doing this for the longer form preview theme later.

  • Closures other than for string, bool, date, and filesize are currently only displayed as a summary. There aren't any themes currently that this impacts, but if you create one manually, the display results were pretty bad. This is primarily due to bad indentation from config.nu (and/or defaults). A proper nu-indent would help fix this, or maybe we could just remove all whitespace and display any closure as a one-liner.

I probably won't regenerate screenshots until we figure out what to do about the "monotone" type colors.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

Maybe background should say "background - color (shown as foreground here)" or something to that affect?

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

Maybe background should say "background - color (shown as foreground here)" or something to that affect?

Maybe, but it really seems we're overcomplicating it. I mean, the background color itself (the color representation) is pretty clearly visible as the background of the whole screen. Our only quandary is how to display the textual representation of the color. We've gone through all three possibilities, I believe:

  1. Background color on background (unreadable)
  2. Foreground color on background (default/normal)
  3. Background color on foreground (inverted)

After looking at the inverted form for a day, I'm thinking that the second was the most clear, and really didn't need explanation since "background" is such an obvious concept.

I can add "explanation" text, but I'd honestly rather not, as (a) it's unwieldy no matter how we word it, (b) the "special-casing" then extends to the text itself in addition to the foreground/background colors.

Mind if I go back to scheme 2 and punt on explanation? I think users will understand ;-)

Edit: Also a possibility - Special-case it so that we have something like foreground/background - <color> on <color>

@NotTheDr01ds
Copy link
Contributor Author

Also about to put in a change on make.nu that will update the "type" colors to match their shapes. I think (at least for a first pass) that I'm going to strip the "bold" attribute, if it exists on the shape.

For types without a corresponding shape, I'll pick something and we'll see how it looks.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

After looking at the inverted form for a day, I'm thinking that the second was the most clear...

Just pick one. I'll go with your recommendation.

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

How about this:

3024-night-new

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

ok.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

one last thing. have you checked to make sure that is the current complete list of shapes and data types? I think there may be some shapes missing.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

here's the flat shapes that are missing

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

here's the flat shapes that are missing

Ah, nope - Those were all added and yet the themes never updated. That's not really a bug in the preview, but in make.nu, of course.

Dang - Gotta pick colors for those now ...

Someone needs to manually update the existing "custom" themes, too.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

here's a list for the types that are missing

glob
closure
custom

i'm not sure if it works if these are added or not. it may also be a good idea to put the types in alphabetical order except for the ones in the 3rd column. the 3rd columns ones should also probably be singular instead of plural. sorry to nit-pick so much.

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

a good idea to put the types in alphabetical order

Yeah, thought about that (as a future feature) - Would be best/nice if they were defined in $env.config.color_config in alpha-order. So I might try to change that in make.nu as well and see how close I can get.

Edit: I'd like to hold off on that for the moment for this particular PR, if that's okay.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

if that's okay.

Sure, no worries at all. We can land this when you're ready and keep working on it. Just ping me when you're ready.

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

Is there really not a shape_comment? The parser seems to change colors on a CLI comment, but I don't see that it can be styled.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

Is there really not a shape_comment? The parser seems to change colors on a CLI comment, but I don't see that it can be styled.

I'm not exactly sure how it's styled. It must be in the parsing or there's some ad-hoc thing like shape_matching_brackets somewhere.

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

Additional changes pushed to make.nu:

  • Adds in missing shapes and types
  • Adds colors for types - Mostly matching the corresponding shape, but with any attribute (e.g., bold) removed
  • Changed int and float types and shapes to be distinct. In most themes, the colors should be close and complementary.
  • Alphabetizes shapes and types so that Previews are also sorted properly
  • Eliminated spurious newline when sourcing theme (from printing OSC codes for terminal colors)

@NotTheDr01ds
Copy link
Contributor Author

NotTheDr01ds commented Jul 29, 2024

Note: Still not ready to land even if you are okay with these updates. Still need to push the changes to the themes themselves (update with new ./make.nu) as well as generate new screenshots. Just want to wait on those mega-pushes until everything else looks good.

@NotTheDr01ds
Copy link
Contributor Author

Oh, and I keep forgetting to cc @amtoine since you've done so much on the themes as well.

@amtoine
Copy link
Member

amtoine commented Jul 29, 2024

marking this as DRAFT as per the PR description

@amtoine amtoine marked this pull request as draft July 29, 2024 17:59
Copy link
Member

@amtoine amtoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the theme preview is more @fdncred 's territory, but the rest looks fine to me, thanks @NotTheDr01ds for thinking about pinging me 🙏

@NotTheDr01ds
Copy link
Contributor Author

A couple of more changes coming in the latest (not yet pushed). bool: false and hints were both fixed at "dark_grey", which meant that they wouldn't show up well (or at all) on a lot of themes. I've changed false to color3 (usually a yellow or orange) and hints to color8 (usually a theme-appropriate gray, which should be the case with an SGR-based theming).

A sampling of some light and dark themes below:

dark-pastel
brushtrees
3024-night
dirtysea
dot-gov

If you're good with this, I can push the updated themes and screenshots.

Note: Custom themes have not yet been modified to include the missing types and shapes.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

Looks great. Love the multi-color types. Nice work on all this!

@NotTheDr01ds
Copy link
Contributor Author

Something important to note that I hadn't yet - I chose an underline attribute for vardecl. I personally think this adds a nice touch on variable declarations.

Also:

shape_matching_brackets is not missing but also not in https://github.com/nushell/nushell/blob/d618fd0527c589ca66ea4c8af813e2bbca32ee88/crates/nu-parser/src/flatten.rs#L13 but i'm guessing it still works. not sure why it's not a flat shape

Maybe I'm missing something, but I don't see any style applied when I'm on matching brackets in the REPL.

@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

Maybe I'm missing something, but I don't see any style applied when I'm on matching brackets in the REPL.

matching brackets are supposed to be highlighted as you're typing. maybe it's broken?

@NotTheDr01ds
Copy link
Contributor Author

matching brackets are supposed to be highlighted as you're typing. maybe it's broken?

Agreed

@NotTheDr01ds NotTheDr01ds marked this pull request as ready for review July 29, 2024 21:51
@NotTheDr01ds
Copy link
Contributor Author

Should be ready to land.

New screenshot method using asciinema, agg (converts asciinema to animated gif), and ffmpeg (to get a single frame from the animated gif). Big advantage is that you don't have to keep focus on the terminal while it's running - It can generate everything in the background.

@NotTheDr01ds NotTheDr01ds changed the title preview-theme-small rework Additional Theme Features Jul 29, 2024
@fdncred
Copy link
Collaborator

fdncred commented Jul 29, 2024

let's go!

@fdncred fdncred merged commit 9a12d8d into nushell:main Jul 29, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants