1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! A crate for working with `.attheme` files. It:
//!
//! - Parses `.attheme`;
//! - Serializes `.attheme`;
//! - Deals with both Java integers (e.g. `-609399291`) and HEXes (`#fd5aebbb`);
//! - Parses wallpapers;
//! - Can add themes (`&theme + &other_theme`) and fallback to another one
//!   (`&theme | &other_theme`);
//! - Has the default themes.
//!
//! If you think we don't support something we should or have a question, feel
//! free to fill an issue on [our GitLab repository][gitlab].
//!
//! [gitlab]: https://gitlab.com/snejugal/attheme-rs

#![deny(warnings)]
#![deny(future_incompatible)]
#![deny(nonstandard_style)]

mod attheme;
pub mod default_themes;
mod parser;
mod serializer;

pub use self::attheme::*;
use indexmap::IndexMap;

/// Represents colors.
///
/// The order of channels is `[red, green, blue, alpha]`. An array was chosen
/// so it should be simplier to use this color with other crates, rather than
/// if we used a struct.
pub type Color = [u8; 4];

/// An `IndexMap` storing variables of the theme.
pub type Variables = IndexMap<String, Color>;

/// A `Vec` of bytes that represents the image wallpaper of the theme.
pub type Wallpaper = Vec<u8>;

/// Determines how to serialize colors. Used by [`Attheme.to_bytes`].
///
/// [`Attheme.to_bytes`]: ./struct.Attheme.html#method.to_bytes
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum ColorSignature {
  /// Represents colors as #aarrggbb.
  ///
  /// `[0xff; 4]` becomes `#ffffffff`, `[0x10, 0x20, 0x30, 0x40]` becomes
  /// `#40102030`.
  Hex,
  /// Represents colors as Java Color Integers.
  ///
  /// `[0xff; 4]` becomes `-1`, and `[0x10, 0x20, 0x30, 0x40]` becomes
  /// `1074798640`. See the [guide to .attheme's] to learn about this color
  /// representation.
  ///
  /// [guide to .attheme's]: telegra.ph/Complete-guide-to-Android-Telegram-theming-12-31#Text-editors
  Int,
}