diff --git a/assets/gear-64x64.bmp b/assets/gear-64x64.bmp new file mode 100644 index 0000000..962ec6e Binary files /dev/null and b/assets/gear-64x64.bmp differ diff --git a/assets/gear-64x64.png b/assets/gear-64x64.png new file mode 100644 index 0000000..0911c7a Binary files /dev/null and b/assets/gear-64x64.png differ diff --git a/assets/gear-64x64.raw b/assets/gear-64x64.raw new file mode 100644 index 0000000..21b478d Binary files /dev/null and b/assets/gear-64x64.raw differ diff --git a/assets/gear.jpg b/assets/gear.jpg new file mode 100644 index 0000000..5456a99 Binary files /dev/null and b/assets/gear.jpg differ diff --git a/src/app/mod.rs b/src/app/mod.rs index f9c5124..db903c0 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -14,14 +14,14 @@ use sdl2::hint; use sdl2::keyboard::{Keycode, Mod}; use sdl2::mouse::MouseButton; use sdl2::pixels::{Color, PixelFormatEnum}; -use sdl2::surface::Surface; use sdl2::rect::{Point, Rect}; use sdl2::render::Canvas; +use sdl2::rwops::RWops; +use sdl2::surface::Surface; use sdl2::ttf::Sdl2TtfContext; use sdl2::video::Window; use sdl2::EventPump; use sdl2::{Sdl, TimerSubsystem, VideoSubsystem}; -use sdl2::rwops::RWops; pub mod app_state; pub mod caret_manager; @@ -81,10 +81,6 @@ impl Application { let icon_bytes = include_bytes!("../../assets/gear-64x64.bmp").clone(); let mut rw = RWops::from_bytes(&icon_bytes).unwrap(); let mut icon = Surface::load_bmp_rw(&mut rw).unwrap(); -// let mut icon = Surface::from_data( -// &mut icon_bytes, -// 64, 64, 64, PixelFormatEnum::RGB24 -// ).unwrap(); window.set_icon(&mut icon); let canvas = window.into_canvas().accelerated().build().unwrap(); diff --git a/src/themes/caret_color.rs b/src/themes/caret_color.rs new file mode 100644 index 0000000..a93ee08 --- /dev/null +++ b/src/themes/caret_color.rs @@ -0,0 +1,39 @@ +use crate::themes::SerdeColor; +use crate::themes::ThemeConfig; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct CaretColor { + bright: ThemeConfig, + blur: ThemeConfig, +} + +impl Default for CaretColor { + fn default() -> Self { + Self { + bright: ThemeConfig::new( + SerdeColor::new(0, 0, 0, 0), + false, + false, + ), + blur: ThemeConfig::new( + SerdeColor::new(0, 0, 0, 0), + false, + false, + ), + } + } +} + +impl CaretColor { + pub fn new(bright: ThemeConfig, blur: ThemeConfig) -> Self { + Self { bright, blur } + } + + pub fn bright(&self) -> &ThemeConfig { + &self.bright + } + + pub fn blur(&self) -> &ThemeConfig { + &self.blur + } +} diff --git a/src/themes/code_highlighting_color.rs b/src/themes/code_highlighting_color.rs new file mode 100644 index 0000000..4ae0def --- /dev/null +++ b/src/themes/code_highlighting_color.rs @@ -0,0 +1,123 @@ +use crate::themes::SerdeColor; +use crate::themes::ThemeConfig; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct CodeHighlightingColor { + pub comment: ThemeConfig, + pub constant: ThemeConfig, + pub error: ThemeConfig, + pub warning: ThemeConfig, + pub identifier: ThemeConfig, + pub keyword: ThemeConfig, + pub literal: ThemeConfig, + pub number: ThemeConfig, + pub operator: ThemeConfig, + pub separator: ThemeConfig, + pub statement: ThemeConfig, + pub string: ThemeConfig, + pub title: ThemeConfig, + pub type_: ThemeConfig, + pub todo: ThemeConfig, + pub pre_proc: ThemeConfig, + pub special: ThemeConfig, + pub whitespace: ThemeConfig, +} + +impl Default for CodeHighlightingColor { + fn default() -> Self { + Self { + comment: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + constant: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + error: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + warning: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + identifier: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + keyword: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + literal: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + number: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + operator: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + separator: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + statement: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + string: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + title: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + type_: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + todo: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + pre_proc: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + special: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + whitespace: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + } + } +} + +impl CodeHighlightingColor { + pub fn comment(&self) -> &ThemeConfig { + &self.comment + } + + pub fn constant(&self) -> &ThemeConfig { + &self.constant + } + + pub fn error(&self) -> &ThemeConfig { + &self.error + } + + pub fn warning(&self) -> &ThemeConfig { + &self.warning + } + + pub fn identifier(&self) -> &ThemeConfig { + &self.identifier + } + + pub fn keyword(&self) -> &ThemeConfig { + &self.keyword + } + + pub fn literal(&self) -> &ThemeConfig { + &self.literal + } + + pub fn number(&self) -> &ThemeConfig { + &self.number + } + + pub fn operator(&self) -> &ThemeConfig { + &self.operator + } + + pub fn separator(&self) -> &ThemeConfig { + &self.separator + } + + pub fn statement(&self) -> &ThemeConfig { + &self.statement + } + + pub fn string(&self) -> &ThemeConfig { + &self.string + } + + pub fn title(&self) -> &ThemeConfig { + &self.title + } + + pub fn type_(&self) -> &ThemeConfig { + &self.type_ + } + + pub fn todo(&self) -> &ThemeConfig { + &self.todo + } + + pub fn pre_proc(&self) -> &ThemeConfig { + &self.pre_proc + } + + pub fn special(&self) -> &ThemeConfig { + &self.special + } + + pub fn whitespace(&self) -> &ThemeConfig { + &self.whitespace + } +} diff --git a/src/themes/config_creator.rs b/src/themes/config_creator.rs index 9d0d4a1..70b750f 100644 --- a/src/themes/config_creator.rs +++ b/src/themes/config_creator.rs @@ -1,4 +1,5 @@ use crate::config::directories::*; +use crate::themes::predef::*; use crate::themes::*; use dirs; use std::fs; @@ -14,142 +15,142 @@ pub fn create() { fn write_theme(theme: &Theme) { let mut theme_path = themes_dir(); - theme_path.push(format!("{}.json", theme.name)); + theme_path.push(format!("{}.json", theme.name())); let contents = serde_json::to_string_pretty(&theme).unwrap(); fs::write(&theme_path, contents.clone()) .unwrap_or_else(|_| panic!("Failed to crate theme config file")); } fn default_styles() -> Vec { - vec![default_theme(), railscasts_theme()] + vec![default::build_theme(), railscasts::build_theme()] } -fn default_theme() -> Theme { - Theme::default() -} +//fn default_theme() -> Theme { +// Theme::default() +//} -fn railscasts_theme() -> Theme { - Theme { - name: "railscasts".to_string(), - background: SerdeColor { - r: 60, - g: 60, - b: 60, - a: 0, - }, - caret: CaretColor { - bright: ThemeConfig { - color: SerdeColor { - r: 121, - g: 121, - b: 121, - a: 0, - }, - italic: false, - bold: false, - }, - blur: ThemeConfig { - color: SerdeColor { - r: 21, - g: 21, - b: 21, - a: 0, - }, - italic: false, - bold: false, - }, - }, - code_highlighting: CodeHighlightingColor { - whitespace: ThemeConfig { - color: SerdeColor { - r: 220, - g: 220, - b: 220, - a: 90, - }, - italic: false, - bold: false, - }, - keyword: ThemeConfig { - color: SerdeColor { - r: 203, - g: 120, - b: 50, - a: 0, - }, - italic: false, - bold: true, - }, - string: ThemeConfig { - color: SerdeColor { - r: 164, - g: 194, - b: 96, - a: 0, - }, - italic: false, - bold: false, - }, - number: ThemeConfig { - color: SerdeColor { - r: 164, - g: 194, - b: 96, - a: 0, - }, - italic: false, - bold: false, - }, - identifier: ThemeConfig { - color: SerdeColor { - r: 121, - g: 121, - b: 121, - a: 0, - }, - italic: false, - bold: false, - }, - literal: ThemeConfig { - color: SerdeColor { - r: 121, - g: 121, - b: 121, - a: 0, - }, - italic: false, - bold: false, - }, - comment: ThemeConfig { - color: SerdeColor { - r: 188, - g: 147, - b: 88, - a: 0, - }, - italic: true, - bold: false, - }, - operator: ThemeConfig { - color: SerdeColor { - r: 200, - g: 0, - b: 0, - a: 0, - }, - italic: false, - bold: false, - }, - separator: ThemeConfig { - color: SerdeColor { - r: 221, - g: 221, - b: 221, - a: 0, - }, - italic: false, - bold: false, - }, - }, - } -} +//fn railscasts_theme() -> Theme { +// Theme { +// name: "railscasts".to_string(), +// background: SerdeColor { +// r: 60, +// g: 60, +// b: 60, +// a: 0, +// }, +// caret: CaretColor { +// bright: ThemeConfig { +// color: SerdeColor { +// r: 121, +// g: 121, +// b: 121, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// blur: ThemeConfig { +// color: SerdeColor { +// r: 21, +// g: 21, +// b: 21, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// }, +// code_highlighting: CodeHighlightingColor { +// whitespace: ThemeConfig { +// color: SerdeColor { +// r: 220, +// g: 220, +// b: 220, +// a: 90, +// }, +// italic: false, +// bold: false, +// }, +// keyword: ThemeConfig { +// color: SerdeColor { +// r: 175, +// g: 95, +// b: 0, +// a: 0, +// }, +// italic: false, +// bold: true, +// }, +// string: ThemeConfig { +// color: SerdeColor { +// r: 135, +// g: 175, +// b: 95, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// number: ThemeConfig { +// color: SerdeColor { +// r: 135, +// g: 175, +// b: 95, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// identifier: ThemeConfig { +// color: SerdeColor { +// r: 175, +// g: 75, +// b: 75, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// literal: ThemeConfig { +// color: SerdeColor { +// r: 121, +// g: 121, +// b: 121, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// comment: ThemeConfig { +// color: SerdeColor { +// r: 175, +// g: 135, +// b: 95, +// a: 0, +// }, +// italic: true, +// bold: false, +// }, +// operator: ThemeConfig { +// color: SerdeColor { +// r: 200, +// g: 0, +// b: 0, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// separator: ThemeConfig { +// color: SerdeColor { +// r: 221, +// g: 221, +// b: 221, +// a: 0, +// }, +// italic: false, +// bold: false, +// }, +// }, +// } +//} diff --git a/src/themes/diff_color.rs b/src/themes/diff_color.rs new file mode 100644 index 0000000..398df64 --- /dev/null +++ b/src/themes/diff_color.rs @@ -0,0 +1,37 @@ +use crate::themes::SerdeColor; +use crate::themes::ThemeConfig; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct DiffColor { + pub add: ThemeConfig, + pub delete: ThemeConfig, + pub change: ThemeConfig, + pub text: ThemeConfig, +} + +impl Default for DiffColor { + fn default() -> Self { + Self { + add: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + delete: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + change: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + text: ThemeConfig::new(SerdeColor::new(0, 0, 0, 0), false, false), + } + } +} + +impl DiffColor { + pub fn new( + add: ThemeConfig, + delete: ThemeConfig, + change: ThemeConfig, + text: ThemeConfig, + ) -> Self { + Self { + add, + delete, + change, + text, + } + } +} diff --git a/src/themes/mod.rs b/src/themes/mod.rs index 6819cd2..ef08ffb 100644 --- a/src/themes/mod.rs +++ b/src/themes/mod.rs @@ -6,249 +6,18 @@ use std::env; use std::fs; use std::path::PathBuf; +pub mod caret_color; +pub mod code_highlighting_color; pub mod config_creator; +pub mod diff_color; +pub mod predef; +pub mod serde_color; +pub mod theme; +pub mod theme_config; -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] -pub struct SerdeColor { - pub r: u8, - pub g: u8, - pub b: u8, - pub a: u8, -} - -impl SerdeColor { - pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self { - Self { r, g, b, a } - } -} - -impl Into for &SerdeColor { - fn into(self) -> Color { - Color { - r: self.r, - g: self.g, - b: self.b, - a: self.a, - } - } -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] -pub struct ThemeConfig { - color: SerdeColor, - italic: bool, - bold: bool, -} - -impl ThemeConfig { - pub fn color(&self) -> &SerdeColor { - &self.color - } - - pub fn italic(&self) -> bool { - self.italic - } - - pub fn bold(&self) -> bool { - self.bold - } -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] -pub struct CaretColor { - bright: ThemeConfig, - blur: ThemeConfig, -} - -impl Default for CaretColor { - fn default() -> Self { - Self { - bright: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - italic: false, - bold: false, - }, - blur: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - italic: false, - bold: false, - }, - } - } -} - -impl CaretColor { - pub fn bright(&self) -> &ThemeConfig { - &self.bright - } - - pub fn blur(&self) -> &ThemeConfig { - &self.blur - } -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] -pub struct CodeHighlightingColor { - whitespace: ThemeConfig, - keyword: ThemeConfig, - string: ThemeConfig, - number: ThemeConfig, - identifier: ThemeConfig, - literal: ThemeConfig, - comment: ThemeConfig, - operator: ThemeConfig, - separator: ThemeConfig, -} - -impl Default for CodeHighlightingColor { - fn default() -> Self { - Self { - whitespace: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - keyword: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - string: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - number: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - identifier: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - literal: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - comment: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - operator: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - separator: ThemeConfig { - color: SerdeColor::new(0, 0, 0, 0), - bold: false, - italic: false, - }, - } - } -} - -impl CodeHighlightingColor { - pub fn whitespace(&self) -> &ThemeConfig { - &self.whitespace - } - - pub fn keyword(&self) -> &ThemeConfig { - &self.keyword - } - - pub fn string(&self) -> &ThemeConfig { - &self.string - } - - pub fn number(&self) -> &ThemeConfig { - &self.number - } - - pub fn identifier(&self) -> &ThemeConfig { - &self.identifier - } - - pub fn literal(&self) -> &ThemeConfig { - &self.literal - } - - pub fn comment(&self) -> &ThemeConfig { - &self.comment - } - - pub fn operator(&self) -> &ThemeConfig { - &self.operator - } - - pub fn separator(&self) -> &ThemeConfig { - &self.separator - } -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] -pub struct Theme { - name: String, - background: SerdeColor, - caret: CaretColor, - code_highlighting: CodeHighlightingColor, -} - -impl Default for Theme { - fn default() -> Self { - use crate::themes::config_creator; - Self { - name: "default".to_string(), - background: SerdeColor::new(255, 255, 255, 0), - caret: CaretColor::default(), - code_highlighting: CodeHighlightingColor::default(), - } - } -} - -impl Theme { - pub fn name(&self) -> &String { - &self.name - } - - pub fn background(&self) -> &SerdeColor { - &self.background - } - - pub fn caret(&self) -> &CaretColor { - &self.caret - } - - pub fn code_highlighting(&self) -> &CodeHighlightingColor { - &self.code_highlighting - } - - pub fn load(theme_name: String) -> Self { - use dirs; - let home_dir = dirs::config_dir().unwrap(); - let mut config_dir = home_dir.clone(); - config_dir.push("rider"); - fs::create_dir_all(&config_dir) - .unwrap_or_else(|_| panic!("Cannot create config directory")); - Self::load_content(format!("{}.json", theme_name).as_str()) - } - - fn load_content(file_name: &str) -> Theme { - let mut config_file = themes_dir(); - config_file.push(file_name); - let contents = match fs::read_to_string(&config_file) { - Ok(s) => s, - Err(_) => { - use crate::themes::config_creator; - config_creator::create(); - fs::read_to_string(&config_file) - .unwrap_or_else(|_| panic!("Failed to load theme config file")) - } - }; - serde_json::from_str(&contents).unwrap_or_default() - } -} +pub use crate::themes::caret_color::CaretColor; +pub use crate::themes::code_highlighting_color::CodeHighlightingColor; +pub use crate::themes::diff_color::DiffColor; +pub use crate::themes::serde_color::SerdeColor; +pub use crate::themes::theme::Theme; +pub use crate::themes::theme_config::ThemeConfig; diff --git a/src/themes/predef/default.rs b/src/themes/predef/default.rs new file mode 100644 index 0000000..14e6bb2 --- /dev/null +++ b/src/themes/predef/default.rs @@ -0,0 +1,5 @@ +use crate::themes::Theme; + +pub fn build_theme() -> Theme { + Theme::default() +} diff --git a/src/themes/predef/mod.rs b/src/themes/predef/mod.rs new file mode 100644 index 0000000..b6d02fc --- /dev/null +++ b/src/themes/predef/mod.rs @@ -0,0 +1,2 @@ +pub mod default; +pub mod railscasts; diff --git a/src/themes/predef/railscasts.rs b/src/themes/predef/railscasts.rs new file mode 100644 index 0000000..a89f5f9 --- /dev/null +++ b/src/themes/predef/railscasts.rs @@ -0,0 +1,43 @@ +use crate::themes::caret_color::CaretColor; +use crate::themes::CodeHighlightingColor; +use crate::themes::DiffColor; +use crate::themes::SerdeColor; +use crate::themes::Theme; +use crate::themes::ThemeConfig; + +pub fn build_theme() -> Theme { + Theme::new( + "railscasts".to_string(), + SerdeColor::new(18, 18, 18, 0), + CaretColor::new( + ThemeConfig::new(SerdeColor::new(121, 121, 121, 0), false, false), + ThemeConfig::new(SerdeColor::new(21, 21, 21, 0), false, false), + ), + CodeHighlightingColor { + comment: ThemeConfig::new(SerdeColor::new(175, 135, 95, 0), false, false), + constant: ThemeConfig::new(SerdeColor::new(109, 156, 190, 0), false, false), + error: ThemeConfig::new(SerdeColor::new(255, 255, 255, 0), false, false), + warning: ThemeConfig::new(SerdeColor::new(128, 0, 0, 0), false, false), + identifier: ThemeConfig::new(SerdeColor::new(175, 95, 95, 0), false, false), + keyword: ThemeConfig::new(SerdeColor::new(175, 95, 0, 0), false, false), + literal: ThemeConfig::new(SerdeColor::new(228, 228, 228, 0), false, false), + number: ThemeConfig::new(SerdeColor::new(135, 175, 95, 0), false, false), + operator: ThemeConfig::new(SerdeColor::new(228, 228, 228, 0), false, false), + separator: ThemeConfig::new(SerdeColor::new(228, 228, 228, 0), false, false), + statement: ThemeConfig::new(SerdeColor::new(175, 95, 0, 0), false, false), + string: ThemeConfig::new(SerdeColor::new(135, 175, 95, 0), false, false), + title: ThemeConfig::new(SerdeColor::new(255, 255, 255, 0), false, false), + type_: ThemeConfig::new(SerdeColor::new(223, 95, 95, 0), false, false), + todo: ThemeConfig::new(SerdeColor::new(223, 95, 95, 0), false, false), + pre_proc: ThemeConfig::new(SerdeColor::new(255, 135, 0, 0), false, false), + special: ThemeConfig::new(SerdeColor::new(0, 95, 0, 0), false, false), + whitespace: ThemeConfig::new(SerdeColor::new(220, 220, 220, 90), false, false), + }, + DiffColor::new( + ThemeConfig::new(SerdeColor::new(228, 228, 228, 0), false, false), + ThemeConfig::new(SerdeColor::new(102, 0, 0, 0), false, false), + ThemeConfig::new(SerdeColor::new(135, 0, 135, 0), false, false), + ThemeConfig::new(SerdeColor::new(18, 18, 18, 0), false, false), + ), + ) +} diff --git a/src/themes/serde_color.rs b/src/themes/serde_color.rs new file mode 100644 index 0000000..c269de1 --- /dev/null +++ b/src/themes/serde_color.rs @@ -0,0 +1,26 @@ +use sdl2::pixels::Color; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct SerdeColor { + pub r: u8, + pub g: u8, + pub b: u8, + pub a: u8, +} + +impl SerdeColor { + pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self { + Self { r, g, b, a } + } +} + +impl Into for &SerdeColor { + fn into(self) -> Color { + Color { + r: self.r, + g: self.g, + b: self.b, + a: self.a, + } + } +} diff --git a/src/themes/theme.rs b/src/themes/theme.rs new file mode 100644 index 0000000..496c529 --- /dev/null +++ b/src/themes/theme.rs @@ -0,0 +1,91 @@ +use crate::config::directories::themes_dir; +use crate::themes::CaretColor; +use crate::themes::CodeHighlightingColor; +use crate::themes::DiffColor; +use crate::themes::SerdeColor; +use dirs; +use std::fs; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct Theme { + name: String, + background: SerdeColor, + caret: CaretColor, + code_highlighting: CodeHighlightingColor, + diff: DiffColor, +} + +impl Default for Theme { + fn default() -> Self { + use crate::themes::config_creator; + Self { + name: "default".to_string(), + background: SerdeColor::new(255, 255, 255, 0), + caret: CaretColor::default(), + code_highlighting: CodeHighlightingColor::default(), + diff: DiffColor::default(), + } + } +} + +impl Theme { + pub fn new( + name: String, + background: SerdeColor, + caret: CaretColor, + code_highlighting: CodeHighlightingColor, + diff: DiffColor, + ) -> Self { + Self { + name, + background, + caret, + code_highlighting, + diff, + } + } + + pub fn name(&self) -> &String { + &self.name + } + + pub fn background(&self) -> &SerdeColor { + &self.background + } + + pub fn caret(&self) -> &CaretColor { + &self.caret + } + + pub fn diff(&self) -> &DiffColor { + &self.diff + } + + pub fn code_highlighting(&self) -> &CodeHighlightingColor { + &self.code_highlighting + } + + pub fn load(theme_name: String) -> Self { + let home_dir = dirs::config_dir().unwrap(); + let mut config_dir = home_dir.clone(); + config_dir.push("rider"); + fs::create_dir_all(&config_dir) + .unwrap_or_else(|_| panic!("Cannot create config directory")); + Self::load_content(format!("{}.json", theme_name).as_str()) + } + + fn load_content(file_name: &str) -> Theme { + let mut config_file = themes_dir(); + config_file.push(file_name); + let contents = match fs::read_to_string(&config_file) { + Ok(s) => s, + Err(_) => { + use crate::themes::config_creator; + config_creator::create(); + fs::read_to_string(&config_file) + .unwrap_or_else(|_| panic!("Failed to load theme config file")) + } + }; + serde_json::from_str(&contents).unwrap_or_default() + } +} diff --git a/src/themes/theme_config.rs b/src/themes/theme_config.rs new file mode 100644 index 0000000..66e542a --- /dev/null +++ b/src/themes/theme_config.rs @@ -0,0 +1,30 @@ +use crate::themes::SerdeColor; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct ThemeConfig { + color: SerdeColor, + italic: bool, + bold: bool, +} + +impl ThemeConfig { + pub fn new(color: SerdeColor, italic: bool, bold: bool) -> Self { + Self { + color, + italic, + bold, + } + } + + pub fn color(&self) -> &SerdeColor { + &self.color + } + + pub fn italic(&self) -> bool { + self.italic + } + + pub fn bold(&self) -> bool { + self.bold + } +} diff --git a/src/ui/caret.rs b/src/ui/caret.rs index 4eb22f4..cd54920 100644 --- a/src/ui/caret.rs +++ b/src/ui/caret.rs @@ -121,6 +121,10 @@ pub struct CaretColor { } impl CaretColor { + pub fn new(bright: Color, blur: Color) -> Self { + Self { bright, blur } + } + pub fn bright(&self) -> &Color { &self.bright }