Skip to content

Instantly share code, notes, and snippets.

@El-Wumbus
Created December 23, 2024 03:19
Show Gist options
  • Save El-Wumbus/f66d7e3f599a8a8a1a608dc256b95ab5 to your computer and use it in GitHub Desktop.
Save El-Wumbus/f66d7e3f599a8a8a1a608dc256b95ab5 to your computer and use it in GitHub Desktop.
Translate GIMP Palette files into CSS.
//! Translate [GIMP Palette Format Version 2 (.gpl)](https://developer.gimp.org/core/standards/gpl/) files into CSS variables.
use std::io::BufRead;
fn main() {
let stdin = std::io::BufReader::new(std::io::stdin());
for line in stdin.lines().skip(1) {
let line = line.unwrap();
let line = line.trim();
if line.is_empty() || line.starts_with("#") || line.starts_with("Name:") || line.starts_with("Columns:") { continue; }
let (r, rest) = line.split_once(char::is_whitespace).unwrap();
let (g, rest) = rest.trim_start().split_once(char::is_whitespace).unwrap();
let (b, rest) = rest.trim_start().split_once(char::is_whitespace).unwrap();
let name = rest.trim().replace(char::is_whitespace, "-");
let (r, g, b): (u8, u8, u8) = (r.parse().unwrap(), g.parse().unwrap(), b.parse().unwrap());
println!("--{name}: rgb({r}, {g}, {b});");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment