mod keymap;
mod theme;
pub use keymap::{Action, Keymap};
pub use theme::{Appearance, Groups};
#[derive(Clone, Copy, Debug)]
pub struct Settings {
pub max_input_height_percent: u8,
pub input_scrolloff: u8,
pub statusline: StatusLinePosition,
}
impl Default for Settings {
fn default() -> Self {
Self {
max_input_height_percent: 75,
input_scrolloff: 2,
statusline: StatusLinePosition::default(),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum StatusLinePosition {
#[default]
BelowInput,
AboveInput,
Off,
}
impl StatusLinePosition {
const fn cycle(self, delta: i8) -> Self {
match (self, delta > 0) {
(Self::BelowInput, true) | (Self::Off, false) => Self::AboveInput,
(Self::AboveInput, true) => Self::Off,
(Self::AboveInput, false) => Self::BelowInput,
(Self::Off, true) => Self::BelowInput,
(Self::BelowInput, false) => Self::Off,
}
}
}
#[derive(Clone, Copy, PartialEq)]
pub enum SettingField {
MaxInputHeight,
InputScrolloff,
StatusLine,
}
impl SettingField {
pub fn label(self) -> &'static str {
match self {
Self::MaxInputHeight => "max input height",
Self::InputScrolloff => "scrolloff",
Self::StatusLine => "statusline",
}
}
pub fn value(self, settings: &Settings) -> String {
match self {
Self::MaxInputHeight => format!("{}%", settings.max_input_height_percent),
Self::InputScrolloff => format!("{} rows", settings.input_scrolloff),
Self::StatusLine => match settings.statusline {
StatusLinePosition::BelowInput => "below input",
StatusLinePosition::AboveInput => "above input",
StatusLinePosition::Off => "off",
}
.to_string(),
}
}
pub fn adjust(self, settings: &mut Settings, delta: i8) {
if self == Self::StatusLine {
settings.statusline = settings.statusline.cycle(delta);
return;
}
let step = delta
.unsigned_abs()
.saturating_mul(if self == Self::MaxInputHeight { 5 } else { 1 });
let field = match self {
Self::MaxInputHeight => &mut settings.max_input_height_percent,
Self::InputScrolloff => &mut settings.input_scrolloff,
Self::StatusLine => unreachable!("statusline is adjusted above"),
};
*field = if delta > 0 {
field.saturating_add(step)
} else {
field.saturating_sub(step)
};
settings.max_input_height_percent = settings.max_input_height_percent.min(100);
}
}