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

feat: tinty list --json #94

Merged
merged 22 commits into from
Jan 18, 2025
Merged

Conversation

bezhermoso
Copy link
Member

@bezhermoso bezhermoso commented Jan 17, 2025

Description

Produce a machine-readable list of schemes in the form of JSON. Each object in the array exposes a lot of data about the scheme:

  1. id - The unique identifier of the scheme e.g. base16-gruvbox-material-dark-hard
  2. name - The name of the scheme e.g. Gruvbox Material Dark, Hard
  3. slug - The name, slugified e.g. gruvbox-material-dark-hard
  4. system - base16 vs base24
  5. variant - light vs dark
  6. author - The author
  7. palette - The color palette, keyed by base[a-z0-F]{2}:
    1. hex_str - The hex string e.g. #ffffff
    2. hex - The hex components
    3. rgb - The RGB values
    4. dec - RGB values as 8-bit in decimal (rgb / 255)
  8. lightness - Perceived lightness of background and foreground colors, based on their luminance.

Progress

  • Implementation
  • Documentation
  • Tests

Example

tinty list --json | jq '.[] | select(.id == "base16-gruvbox-material-dark-hard")'

Output

{
  "id": "base16-gruvbox-material-dark-hard",
  "name": "Gruvbox Material Dark, Hard",
  "author": "Mayush Kumar (https://github.com/MayushKumar), sainnhe (https://github.com/sainnhe/gruvbox-material-vscode)",
  "system": "base16",
  "variant": "dark",
  "slug": "gruvbox-material-dark-hard",
  "palette": {
    "base0C": {
      "hex_str": "#89b482",
      "hex": [
        "89",
        "b4",
        "82"
      ],
      "rgb": [
        137,
        180,
        130
      ],
      "dec": [
        0.5372549,
        0.7058824,
        0.50980395
      ]
    },
    "base03": {
      "hex_str": "#5a524c",
      "hex": [
        "5a",
        "52",
        "4c"
      ],
      "rgb": [
        90,
        82,
        76
      ],
      "dec": [
        0.3529412,
        0.32156864,
        0.29803923
      ]
    },
    "base02": {
      "hex_str": "#504945",
      "hex": [
        "50",
        "49",
        "45"
      ],
      "rgb": [
        80,
        73,
        69
      ],
      "dec": [
        0.3137255,
        0.28627452,
        0.27058825
      ]
    },
    "base00": {
      "hex_str": "#202020",
      "hex": [
        "20",
        "20",
        "20"
      ],
      "rgb": [
        32,
        32,
        32
      ],
      "dec": [
        0.1254902,
        0.1254902,
        0.1254902
      ]
    },
    "base09": {
      "hex_str": "#e78a4e",
      "hex": [
        "e7",
        "8a",
        "4e"
      ],
      "rgb": [
        231,
        138,
        78
      ],
      "dec": [
        0.90588236,
        0.5411765,
        0.30588236
      ]
    },
    "base0E": {
      "hex_str": "#d3869b",
      "hex": [
        "d3",
        "86",
        "9b"
      ],
      "rgb": [
        211,
        134,
        155
      ],
      "dec": [
        0.827451,
        0.5254902,
        0.60784316
      ]
    },
    "base06": {
      "hex_str": "#ebdbb2",
      "hex": [
        "eb",
        "db",
        "b2"
      ],
      "rgb": [
        235,
        219,
        178
      ],
      "dec": [
        0.92156863,
        0.85882354,
        0.69803923
      ]
    },
    "base0A": {
      "hex_str": "#d8a657",
      "hex": [
        "d8",
        "a6",
        "57"
      ],
      "rgb": [
        216,
        166,
        87
      ],
      "dec": [
        0.84705883,
        0.6509804,
        0.34117648
      ]
    },
    "base01": {
      "hex_str": "#2a2827",
      "hex": [
        "2a",
        "28",
        "27"
      ],
      "rgb": [
        42,
        40,
        39
      ],
      "dec": [
        0.16470589,
        0.15686275,
        0.15294118
      ]
    },
    "base04": {
      "hex_str": "#bdae93",
      "hex": [
        "bd",
        "ae",
        "93"
      ],
      "rgb": [
        189,
        174,
        147
      ],
      "dec": [
        0.7411765,
        0.68235296,
        0.5764706
      ]
    },
    "base0F": {
      "hex_str": "#bd6f3e",
      "hex": [
        "bd",
        "6f",
        "3e"
      ],
      "rgb": [
        189,
        111,
        62
      ],
      "dec": [
        0.7411765,
        0.43529412,
        0.24313726
      ]
    },
    "base0D": {
      "hex_str": "#7daea3",
      "hex": [
        "7d",
        "ae",
        "a3"
      ],
      "rgb": [
        125,
        174,
        163
      ],
      "dec": [
        0.49019608,
        0.68235296,
        0.6392157
      ]
    },
    "base07": {
      "hex_str": "#fbf1c7",
      "hex": [
        "fb",
        "f1",
        "c7"
      ],
      "rgb": [
        251,
        241,
        199
      ],
      "dec": [
        0.9843137,
        0.94509804,
        0.78039217
      ]
    },
    "base08": {
      "hex_str": "#ea6962",
      "hex": [
        "ea",
        "69",
        "62"
      ],
      "rgb": [
        234,
        105,
        98
      ],
      "dec": [
        0.91764706,
        0.4117647,
        0.38431373
      ]
    },
    "base05": {
      "hex_str": "#ddc7a1",
      "hex": [
        "dd",
        "c7",
        "a1"
      ],
      "rgb": [
        221,
        199,
        161
      ],
      "dec": [
        0.8666667,
        0.78039217,
        0.6313726
      ]
    },
    "base0B": {
      "hex_str": "#a9b665",
      "hex": [
        "a9",
        "b6",
        "65"
      ],
      "rgb": [
        169,
        182,
        101
      ],
      "dec": [
        0.6627451,
        0.7137255,
        0.39607844
      ]
    }
  },
  "lightness": {
    "foreground": 81.177246,
    "background": 12.250029
  }
}

@bezhermoso bezhermoso requested a review from a team as a code owner January 17, 2025 03:37
@bezhermoso bezhermoso requested review from JamyGolden and removed request for a team January 17, 2025 03:37
@bezhermoso bezhermoso marked this pull request as draft January 17, 2025 05:00
@bezhermoso bezhermoso marked this pull request as ready for review January 17, 2025 05:30
@bezhermoso
Copy link
Member Author

Accommodates desired use-cases like #74, which would be done as follows:

# Print schemes in bg lightness order, from darkest to lightest
tinty list --json | jq 'sort_by(.lightness.background) | .[] | .id' -r

src/utils.rs Outdated Show resolved Hide resolved
Copy link
Member

@JamyGolden JamyGolden left a comment

Choose a reason for hiding this comment

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

Looks really good! 1 question/comment

src/utils.rs Outdated
pub fn get_all_scheme_file_paths(
schemes_path: &Path,
scheme_systems_option: Option<SchemeSystem>,
) -> Result<HashMap<String, (PathBuf, SchemeFile)>> {
Copy link
Member

Choose a reason for hiding this comment

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

I think this return value is redundant (let me know if I'm missing something). SchemeFile is an enum which contains Yaml(PathBuf) or Yml(PathBuf), so this return value could be:

Suggested change
) -> Result<HashMap<String, (PathBuf, SchemeFile)>> {
) -> Result<HashMap<String, SchemeFile>> {

@JamyGolden
Copy link
Member

JamyGolden commented Jan 17, 2025

Nice! I'll merge after you add the documentation, changelog entry (under ## Unreleased) and tests

@bezhermoso
Copy link
Member Author

@JamyGolden Done!

Copy link
Member

@JamyGolden JamyGolden left a comment

Choose a reason for hiding this comment

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

Great work! I'll create a release after merging

@JamyGolden JamyGolden merged commit e4d702a into tinted-theming:main Jan 18, 2025
5 checks passed
@JamyGolden
Copy link
Member

Published as 0.26.0

@JamyGolden
Copy link
Member

Btw if you're interested in being a maintainer of Tinty, let me know and I'll add you.

@bezhermoso
Copy link
Member Author

@JamyGolden Yeah I'd love to help around here to move the project forward w/ y'all. I'll take your offer, thanks!

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.

2 participants