Skip to content

Theme preview doesn't show "string" label when a closure is used in color_config #919

Open

Description

@NotTheDr01ds

Trying out an example from @fdncred where:

$env.config.color_config.string = {|x| if $x =~ '^#[a-fA-F\d]+' { $x } else { 'default' } 

If that's set in a theme, the theme preview small shows the closure, but doesn't label it as the string type. All the types with basic (or record) colors show the labels.

On the bright side, none of the current themes use a closure for anything other than date, filesize, and bool, and all of those expand their values instead of showing the closure value. Still, if someone has their color_config set like this, the theme preview will be off. Even if the label was shown properly, attempting to display the closure itself inside the table is going to be problematic from a formatting standpoint. Probably need a different solution here.

Activity

  1. fdncred commented on Jul 26, 2024

    @fdncred
    Contributor

    The data type is a closure, not a string. Maybe I'm not following what you're saying.

  2. NotTheDr01ds commented on Jul 26, 2024

    @NotTheDr01ds
    ContributorAuthor

    When it's a closure, the label doesn't show. Probably needs a screenshot demo ;-)

    Normal:

    image

    With closure:

    image

    Notice the "string" label is missing.

  3. NotTheDr01ds commented on Jul 26, 2024

    @NotTheDr01ds
    ContributorAuthor

    The other colors that are conditionally set via closures (date, filesize, and bool) are "special-cased" by the preview script, so it displays a "demo" of the closure results. That isn't possible with other closures, of course, since there's no way in advance to know the pattern(s)/condition(s) in the closure.

  4. fdncred commented on Jul 26, 2024

    @fdncred
    Contributor

    oh, i see what you mean. thanks. i can't remember how i wrote this but is there a way to look at the right hand side and send it to describe to see the data type and then change the output? i think i'll have to look closer at the the script to recall.

  5. NotTheDr01ds commented on Jul 26, 2024

    @NotTheDr01ds
    ContributorAuthor

    Definitely - That's what the code does now, and why it actually prints the view source of the closure rather than just <closure1234>. The fix for the left-side (string label) is probably pretty easy, but I'm just not sure what to print on the right-side that would be helpful + well formatted.

  6. NotTheDr01ds commented on Jul 26, 2024

    @NotTheDr01ds
    ContributorAuthor

    Ah, I just noticed you did special-handle the string closure in preview theme (the uncondensed version). That said, it will only work for your use-case, and not for other conditionals (like the JSON example, if someone did something like that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions