Improve highlights, add icons files

This commit is contained in:
Adrian Wozniak 2019-01-05 09:58:17 +01:00
parent 2632289fc8
commit e77f0366f6
No known key found for this signature in database
GPG Key ID: 3B441F7808FC43C7
17 changed files with 546 additions and 380 deletions

BIN
assets/gear-64x64.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/gear-64x64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
assets/gear-64x64.raw Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
assets/gear.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -14,14 +14,14 @@ use sdl2::hint;
use sdl2::keyboard::{Keycode, Mod}; use sdl2::keyboard::{Keycode, Mod};
use sdl2::mouse::MouseButton; use sdl2::mouse::MouseButton;
use sdl2::pixels::{Color, PixelFormatEnum}; use sdl2::pixels::{Color, PixelFormatEnum};
use sdl2::surface::Surface;
use sdl2::rect::{Point, Rect}; use sdl2::rect::{Point, Rect};
use sdl2::render::Canvas; use sdl2::render::Canvas;
use sdl2::rwops::RWops;
use sdl2::surface::Surface;
use sdl2::ttf::Sdl2TtfContext; use sdl2::ttf::Sdl2TtfContext;
use sdl2::video::Window; use sdl2::video::Window;
use sdl2::EventPump; use sdl2::EventPump;
use sdl2::{Sdl, TimerSubsystem, VideoSubsystem}; use sdl2::{Sdl, TimerSubsystem, VideoSubsystem};
use sdl2::rwops::RWops;
pub mod app_state; pub mod app_state;
pub mod caret_manager; pub mod caret_manager;
@ -81,10 +81,6 @@ impl Application {
let icon_bytes = include_bytes!("../../assets/gear-64x64.bmp").clone(); let icon_bytes = include_bytes!("../../assets/gear-64x64.bmp").clone();
let mut rw = RWops::from_bytes(&icon_bytes).unwrap(); let mut rw = RWops::from_bytes(&icon_bytes).unwrap();
let mut icon = Surface::load_bmp_rw(&mut rw).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); window.set_icon(&mut icon);
let canvas = window.into_canvas().accelerated().build().unwrap(); let canvas = window.into_canvas().accelerated().build().unwrap();

39
src/themes/caret_color.rs Normal file
View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -1,4 +1,5 @@
use crate::config::directories::*; use crate::config::directories::*;
use crate::themes::predef::*;
use crate::themes::*; use crate::themes::*;
use dirs; use dirs;
use std::fs; use std::fs;
@ -14,142 +15,142 @@ pub fn create() {
fn write_theme(theme: &Theme) { fn write_theme(theme: &Theme) {
let mut theme_path = themes_dir(); 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(); let contents = serde_json::to_string_pretty(&theme).unwrap();
fs::write(&theme_path, contents.clone()) fs::write(&theme_path, contents.clone())
.unwrap_or_else(|_| panic!("Failed to crate theme config file")); .unwrap_or_else(|_| panic!("Failed to crate theme config file"));
} }
fn default_styles() -> Vec<Theme> { fn default_styles() -> Vec<Theme> {
vec![default_theme(), railscasts_theme()] vec![default::build_theme(), railscasts::build_theme()]
} }
fn default_theme() -> Theme { //fn default_theme() -> Theme {
Theme::default() // Theme::default()
} //}
fn railscasts_theme() -> Theme { //fn railscasts_theme() -> Theme {
Theme { // Theme {
name: "railscasts".to_string(), // name: "railscasts".to_string(),
background: SerdeColor { // background: SerdeColor {
r: 60, // r: 60,
g: 60, // g: 60,
b: 60, // b: 60,
a: 0, // a: 0,
}, // },
caret: CaretColor { // caret: CaretColor {
bright: ThemeConfig { // bright: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 121, // r: 121,
g: 121, // g: 121,
b: 121, // b: 121,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
blur: ThemeConfig { // blur: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 21, // r: 21,
g: 21, // g: 21,
b: 21, // b: 21,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
}, // },
code_highlighting: CodeHighlightingColor { // code_highlighting: CodeHighlightingColor {
whitespace: ThemeConfig { // whitespace: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 220, // r: 220,
g: 220, // g: 220,
b: 220, // b: 220,
a: 90, // a: 90,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
keyword: ThemeConfig { // keyword: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 203, // r: 175,
g: 120, // g: 95,
b: 50, // b: 0,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: true, // bold: true,
}, // },
string: ThemeConfig { // string: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 164, // r: 135,
g: 194, // g: 175,
b: 96, // b: 95,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
number: ThemeConfig { // number: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 164, // r: 135,
g: 194, // g: 175,
b: 96, // b: 95,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
identifier: ThemeConfig { // identifier: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 121, // r: 175,
g: 121, // g: 75,
b: 121, // b: 75,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
literal: ThemeConfig { // literal: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 121, // r: 121,
g: 121, // g: 121,
b: 121, // b: 121,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
comment: ThemeConfig { // comment: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 188, // r: 175,
g: 147, // g: 135,
b: 88, // b: 95,
a: 0, // a: 0,
}, // },
italic: true, // italic: true,
bold: false, // bold: false,
}, // },
operator: ThemeConfig { // operator: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 200, // r: 200,
g: 0, // g: 0,
b: 0, // b: 0,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
separator: ThemeConfig { // separator: ThemeConfig {
color: SerdeColor { // color: SerdeColor {
r: 221, // r: 221,
g: 221, // g: 221,
b: 221, // b: 221,
a: 0, // a: 0,
}, // },
italic: false, // italic: false,
bold: false, // bold: false,
}, // },
}, // },
} // }
} //}

37
src/themes/diff_color.rs Normal file
View File

@ -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,
}
}
}

View File

@ -6,249 +6,18 @@ use std::env;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
pub mod caret_color;
pub mod code_highlighting_color;
pub mod config_creator; 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 use crate::themes::caret_color::CaretColor;
pub struct SerdeColor { pub use crate::themes::code_highlighting_color::CodeHighlightingColor;
pub r: u8, pub use crate::themes::diff_color::DiffColor;
pub g: u8, pub use crate::themes::serde_color::SerdeColor;
pub b: u8, pub use crate::themes::theme::Theme;
pub a: u8, pub use crate::themes::theme_config::ThemeConfig;
}
impl SerdeColor {
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
}
}
impl Into<Color> 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()
}
}

View File

@ -0,0 +1,5 @@
use crate::themes::Theme;
pub fn build_theme() -> Theme {
Theme::default()
}

2
src/themes/predef/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod default;
pub mod railscasts;

View File

@ -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),
),
)
}

26
src/themes/serde_color.rs Normal file
View File

@ -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<Color> for &SerdeColor {
fn into(self) -> Color {
Color {
r: self.r,
g: self.g,
b: self.b,
a: self.a,
}
}
}

91
src/themes/theme.rs Normal file
View File

@ -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()
}
}

View File

@ -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
}
}

View File

@ -121,6 +121,10 @@ pub struct CaretColor {
} }
impl CaretColor { impl CaretColor {
pub fn new(bright: Color, blur: Color) -> Self {
Self { bright, blur }
}
pub fn bright(&self) -> &Color { pub fn bright(&self) -> &Color {
&self.bright &self.bright
} }