Skip to content

Commit

Permalink
refactor: simplify struct names
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 26, 2024
1 parent 9ae9f4b commit 805afa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ To modify colors or highlights, you can update tables and lists in `src/main.rs`

- `Palette` is a struct to define colors. `Palette::default` method constructs the instance. You
can find the color palette inside the function body.
- `ColorschemeWriter` is a struct to generate Vim colorscheme file. `ColorschemeWriter::new` method
- `Colorscheme` is a struct to generate Vim colorscheme file. `ColorschemeWriter::new` method
constructs the definition of highlights. Read the function body to know/modify the highlights for
each syntax items. The terminal colors used in `:terminal` are also defined here.
- `AirlineThemeWriter` is a struct to generate [vim-airline](https://github.com/vim-airline/vim-airline)
- `AirlineTheme` is a struct to generate [vim-airline](https://github.com/vim-airline/vim-airline)
theme file. `AirlineThemeWriter::new` method defines color palettes for each modes.
- `AlacrittyThemeWriter` is a struct to generate [Alacritty](https://alacritty.org/) theme file.
`AlacrittyThemeWriter` defines the terminal ANSI colors.
- `AlacrittyTheme` is a struct to generate [Alacritty](https://alacritty.org/) theme file.
`AlacrittyTheme::new` method defines the terminal ANSI colors.
24 changes: 12 additions & 12 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ fn indent(level: u8) -> &'static str {
}

#[derive(Debug)]
struct ColorschemeWriter<'a> {
struct Colorscheme<'a> {
palette: &'a Palette,
highlightings: &'a [Highlighting],
term_colors: [&'static str; 16],
}

impl<'a> ColorschemeWriter<'a> {
impl<'a> Colorscheme<'a> {
fn new(palette: &'a Palette) -> Self {
macro_rules! highlight {
($name:ident, $fg:expr, $bg:expr, $sp:expr, $attr:ident) => {
Expand Down Expand Up @@ -673,7 +673,7 @@ struct AirlineModeColors<'a> {
}

#[derive(Debug)]
struct AirlineThemeWriter<'a> {
struct AirlineTheme<'a> {
palette: &'a Palette,
modes: HashMap<&'a str, AirlineModeColors<'a>>,
paste: &'a str,
Expand All @@ -682,7 +682,7 @@ struct AirlineThemeWriter<'a> {
warning: (&'a str, &'a str),
}

impl<'a> AirlineThemeWriter<'a> {
impl<'a> AirlineTheme<'a> {
fn new(palette: &'a Palette) -> Self {
// Note: Pairs of strings are color names of (fg, bg)
Self {
Expand Down Expand Up @@ -874,15 +874,15 @@ struct AlacrittyFgColors<'a> {
}

#[derive(Debug)]
struct AlacrittyThemeWriter<'a> {
struct AlacrittyTheme<'a> {
palette: &'a Palette,
background: &'a str,
dim: AlacrittyFgColors<'a>,
normal: AlacrittyFgColors<'a>,
bright: AlacrittyFgColors<'a>,
}

impl<'a> AlacrittyThemeWriter<'a> {
impl<'a> AlacrittyTheme<'a> {
fn new(palette: &'a Palette) -> Self {
Self {
palette,
Expand Down Expand Up @@ -992,21 +992,21 @@ fn write_to_files(dir: &str) -> Result<()> {
let path = join(&[dir, "colors", "spring-night.vim"]);
let file = File::create(&path)
.with_context(|| format!("Could not create colorscheme file: {:?}", &path))?;
ColorschemeWriter::new(&palette)
Colorscheme::new(&palette)
.write_to(&mut BufWriter::new(file))
.with_context(|| format!("While generate colorscheme file {:?}", &path))?;

let path = join(&[dir, "autoload", "airline", "themes", "spring_night.vim"]);
let file = File::create(&path)
.with_context(|| format!("Could not create airline theme file {:?}", &path))?;
AirlineThemeWriter::new(&palette)
AirlineTheme::new(&palette)
.write_to(&mut BufWriter::new(file))
.with_context(|| format!("Could not generate airline theme file {:?}", &path))?;

let path = join(&[dir, "alacritty", "spring_night.toml"]);
let file = File::create(&path)
.with_context(|| format!("Could not create alacritty theme file {:?}", &path))?;
AlacrittyThemeWriter::new(&palette)
AlacrittyTheme::new(&palette)
.write_to(&mut BufWriter::new(file))
.with_context(|| format!("Could not generate alacritty theme file {:?}", &path))
}
Expand All @@ -1015,15 +1015,15 @@ fn write_to_stdout() -> Result<()> {
let palette = Palette::default();
let mut stdout = io::stdout().lock();

ColorschemeWriter::new(&palette)
Colorscheme::new(&palette)
.write_to(&mut stdout)
.context("While writing colorscheme to stdout")?;
writeln!(stdout)?;
AirlineThemeWriter::new(&palette)
AirlineTheme::new(&palette)
.write_to(&mut stdout)
.context("While writing airline theme to stdout")?;
writeln!(stdout)?;
AlacrittyThemeWriter::new(&palette)
AlacrittyTheme::new(&palette)
.write_to(&mut stdout)
.context("While writing alacritty theme to stdout")
}
Expand Down
22 changes: 11 additions & 11 deletions gen/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn test_color_code() {
#[test]
fn test_write_header() {
let palette = Palette(HashMap::new());
let w = ColorschemeWriter::new(&palette);
let w = Colorscheme::new(&palette);
let mut out = vec![];
w.write_header(&mut out).unwrap();
let rendered = str::from_utf8(&out).unwrap();
Expand All @@ -24,7 +24,7 @@ fn test_write_header() {
#[test]
fn test_write_contrast_color_variables() {
let palette = Palette(HashMap::new());
let w = ColorschemeWriter::new(&palette);
let w = Colorscheme::new(&palette);
let mut out = vec![];
w.write_contrast_color_variables(&mut out).unwrap();
assert_eq!(str::from_utf8(&out).unwrap(), "\n");
Expand Down Expand Up @@ -59,7 +59,7 @@ fn test_write_contrast_color_variables() {
},
);
let palette = Palette(m);
let w = ColorschemeWriter::new(&palette);
let w = Colorscheme::new(&palette);
let mut out = vec![];
w.write_contrast_color_variables(&mut out).unwrap();
for (actual, expected) in [
Expand Down Expand Up @@ -122,15 +122,15 @@ fn test_write_highlight() {
},
);
let palette = Palette(m);
let w = ColorschemeWriter::new(&palette);
let w = Colorscheme::new(&palette);
let mut out = vec![];
w.write_highlight(&mut out, &hl, indent).unwrap();
assert_eq!(str::from_utf8(&out).unwrap(), format!("{}\n", expected));
}

// Edge case
let palette = Palette(HashMap::new());
let mut w = ColorschemeWriter::new(&palette);
let mut w = Colorscheme::new(&palette);
w.highlightings = &[];
let mut out = vec![];
w.write_highlightings(&mut out).unwrap();
Expand All @@ -150,7 +150,7 @@ fn test_write_highlights() {
}

let palette = Palette(HashMap::new());
let mut w = ColorschemeWriter::new(&palette);
let mut w = Colorscheme::new(&palette);
let fixed = &[Fixed(hl())];
w.highlightings = fixed;
let mut out = vec![];
Expand All @@ -162,7 +162,7 @@ fn test_write_highlights() {
term: hl(),
}];
let palette = Palette(HashMap::new());
let mut w = ColorschemeWriter::new(&palette);
let mut w = Colorscheme::new(&palette);
w.highlightings = dynamic;
let mut out = vec![];
w.write_highlightings(&mut out).unwrap();
Expand Down Expand Up @@ -197,7 +197,7 @@ fn test_write_term_colors() {
},
);
let palette = Palette(m);
let mut w = ColorschemeWriter::new(&palette);
let mut w = Colorscheme::new(&palette);
w.term_colors = [
"normal", "contrast", "normal", "contrast", "normal", "contrast", "normal", "contrast",
"normal", "contrast", "normal", "contrast", "normal", "contrast", "normal", "contrast",
Expand All @@ -215,7 +215,7 @@ fn test_write_term_colors() {
#[test]
fn test_colorscheme_writer() {
let palette = Palette::default();
let w = ColorschemeWriter::new(&palette);
let w = Colorscheme::new(&palette);

// Check duplicate highlights
let mut unique_check = HashSet::new();
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_write_airline_theme() {
);

let palette = Palette(m);
let w = AirlineThemeWriter {
let w = AirlineTheme {
palette: &palette,
modes: {
let mut m = HashMap::new();
Expand Down Expand Up @@ -408,7 +408,7 @@ fn test_write_alacritty_theme() {
);
let palette = Palette(m);

let w = AlacrittyThemeWriter {
let w = AlacrittyTheme {
palette: &palette,
background: "color1",
dim: AlacrittyFgColors {
Expand Down

0 comments on commit 805afa5

Please sign in to comment.