mirror of https://github.com/sgoudham/neovide.git
refactored editor into multiple files to make things more readable
parent
be7c9f5207
commit
8467ef18ab
@ -0,0 +1,81 @@
|
||||
use std::collections::HashMap;
|
||||
use skulpin::skia_safe::Color4f;
|
||||
|
||||
use super::style::{Style, Colors};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum CursorShape {
|
||||
Block,
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
|
||||
impl CursorShape {
|
||||
pub fn from_type_name(name: &str) -> Option<CursorShape> {
|
||||
match name {
|
||||
"block" => Some(CursorShape::Block),
|
||||
"horizontal" => Some(CursorShape::Horizontal),
|
||||
"vertical" => Some(CursorShape::Vertical),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(new, Debug, Clone, PartialEq)]
|
||||
pub struct CursorMode {
|
||||
#[new(default)]
|
||||
pub shape: Option<CursorShape>,
|
||||
#[new(default)]
|
||||
pub style_id: Option<u64>
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Cursor {
|
||||
pub position: (u64, u64),
|
||||
pub shape: CursorShape,
|
||||
pub style: Option<Style>,
|
||||
pub enabled: bool,
|
||||
pub mode_list: Vec<CursorMode>
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
pub fn new() -> Cursor {
|
||||
Cursor {
|
||||
position: (0, 0),
|
||||
shape: CursorShape::Block,
|
||||
style: Option::<Style>::default(),
|
||||
enabled: true,
|
||||
mode_list: Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn foreground(&self, default_colors: &Colors) -> Color4f {
|
||||
if let Some(style) = &self.style {
|
||||
style.colors.foreground.clone().unwrap_or(default_colors.background.clone().unwrap())
|
||||
} else {
|
||||
default_colors.background.clone().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn background(&self, default_colors: &Colors) -> Color4f {
|
||||
if let Some(style) = &self.style {
|
||||
style.colors.background.clone().unwrap_or(default_colors.foreground.clone().unwrap())
|
||||
} else {
|
||||
default_colors.foreground.clone().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_mode(&mut self, mode_index: u64, styles: &HashMap<u64, Style>) {
|
||||
if let Some(CursorMode { shape, style_id }) = self.mode_list.get(mode_index as usize) {
|
||||
if let Some(shape) = shape {
|
||||
self.shape = shape.clone();
|
||||
}
|
||||
|
||||
if let Some(style_id) = style_id {
|
||||
self.style = styles
|
||||
.get(style_id)
|
||||
.map(|style_reference| style_reference.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
use skulpin::skia_safe::Color4f;
|
||||
|
||||
#[derive(new, PartialEq, Debug, Clone)]
|
||||
pub struct Colors {
|
||||
pub foreground: Option<Color4f>,
|
||||
pub background: Option<Color4f>,
|
||||
pub special: Option<Color4f>
|
||||
}
|
||||
|
||||
#[derive(new, Debug, Clone, PartialEq)]
|
||||
pub struct Style {
|
||||
pub colors: Colors,
|
||||
#[new(default)]
|
||||
pub reverse: bool,
|
||||
#[new(default)]
|
||||
pub italic: bool,
|
||||
#[new(default)]
|
||||
pub bold: bool,
|
||||
#[new(default)]
|
||||
pub strikethrough: bool,
|
||||
#[new(default)]
|
||||
pub underline: bool,
|
||||
#[new(default)]
|
||||
pub undercurl: bool,
|
||||
#[new(default)]
|
||||
pub blend: u8
|
||||
}
|
||||
|
||||
impl Style {
|
||||
pub fn foreground(&self, default_colors: &Colors) -> Color4f {
|
||||
if self.reverse {
|
||||
self.colors.background.clone().unwrap_or(default_colors.background.clone().unwrap())
|
||||
} else {
|
||||
self.colors.foreground.clone().unwrap_or(default_colors.foreground.clone().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn background(&self, default_colors: &Colors) -> Color4f {
|
||||
if self.reverse {
|
||||
self.colors.foreground.clone().unwrap_or(default_colors.foreground.clone().unwrap())
|
||||
} else {
|
||||
self.colors.background.clone().unwrap_or(default_colors.background.clone().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn special(&self, default_colors: &Colors) -> Color4f {
|
||||
self.colors.special.clone().unwrap_or(default_colors.special.clone().unwrap())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue