use serde::{Deserialize, Serialize};
config_enum! {
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum EditorEol {
#[default]
Auto => "auto",
Lf => "lf",
Crlf => "crlf",
}
}
impl EditorEol {
pub fn label(self) -> &'static str {
match self {
EditorEol::Auto => "Auto (keep the file's)",
EditorEol::Lf => "LF",
EditorEol::Crlf => "CRLF",
}
}
pub fn from_label(label: &str) -> Option<EditorEol> {
Self::ALL.iter().copied().find(|e| e.label() == label)
}
}
pub const DEFAULT_EDITOR_TAB_SIZE: u8 = 4;
pub const MIN_EDITOR_TAB_SIZE: u8 = 1;
pub const MAX_EDITOR_TAB_SIZE: u8 = 8;
pub const DEFAULT_MERGE_SIDE_BY_SIDE_MIN_WIDTH: u16 = 100;
pub const MIN_MERGE_SIDE_BY_SIDE_MIN_WIDTH: u16 = 40;
pub const MAX_MERGE_SIDE_BY_SIDE_MIN_WIDTH: u16 = 400;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct MergeConfig {
pub side_by_side_min_width: u16,
}
impl Default for MergeConfig {
fn default() -> Self {
Self {
side_by_side_min_width: DEFAULT_MERGE_SIDE_BY_SIDE_MIN_WIDTH,
}
}
}
impl MergeConfig {
pub fn side_by_side_min_width_clamped(&self) -> u16 {
match self.side_by_side_min_width {
0 => 0,
w => w.clamp(
MIN_MERGE_SIDE_BY_SIDE_MIN_WIDTH,
MAX_MERGE_SIDE_BY_SIDE_MIN_WIDTH,
),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct EditorConfig {
pub tab_size: u8,
pub eol: EditorEol,
pub syntax_highlighting: bool,
pub line_numbers: bool,
pub follow_selection: bool,
}
impl Default for EditorConfig {
fn default() -> Self {
Self {
tab_size: DEFAULT_EDITOR_TAB_SIZE,
eol: EditorEol::Auto,
syntax_highlighting: true,
line_numbers: true,
follow_selection: true,
}
}
}
impl EditorConfig {
pub fn tab_size_clamped(&self) -> u8 {
self.tab_size
.clamp(MIN_EDITOR_TAB_SIZE, MAX_EDITOR_TAB_SIZE)
}
}