Files
mangotune/src/config/types.rs
T
2026-03-30 23:06:06 -04:00

130 lines
2.7 KiB
Rust

use std::path::PathBuf;
/// A single line from a MangoHud config file, preserving its original text.
#[derive(Debug, Clone, PartialEq)]
pub enum ConfigLine {
Comment(String),
Blank,
Option {
key: String,
value: Option<String>,
raw: String,
},
CommentedOption {
key: String,
value: Option<String>,
raw: String,
},
}
/// The current state of an option in the in-memory config.
#[derive(Debug, Clone, PartialEq)]
pub enum ConfigValue {
Absent,
Flag,
Value(String),
Disabled,
}
/// Type system for schema entries.
#[derive(Debug, Clone)]
pub enum OptionType {
Flag,
Bool,
Int {
min: i64,
max: i64,
},
Float {
min: f64,
max: f64,
},
Str {
max_len: usize,
},
Color,
Enum {
variants: Vec<String>,
},
FpsLimitList,
KeyBind,
CommaSepInts,
CommaSepFloats,
CommaSepStrings {
valid_values: Option<Vec<String>>,
},
Path {
must_exist: bool,
must_be_writable: bool,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum GpuVendor {
Any,
AmdOnly,
NvidiaOnly,
IntelOnly,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Category {
Performance,
DisplayFps,
DisplayGpu,
DisplayCpu,
DisplayMemory,
DisplayIoNetwork,
DisplayMisc,
DisplayGraphs,
DisplayBattery,
DisplayMediaPlayer,
DisplayGamescope,
DisplaySteamDeck,
DisplayTimeText,
AppearanceLayout,
AppearanceColors,
AppearanceTypography,
BehaviorKeybindings,
BehaviorFpsLimits,
BehaviorLogging,
BehaviorMisc,
WorkaroundsOpengl,
AdvancedFcat,
AdvancedFtrace,
}
/// A single schema entry — defines everything about one MangoHud option.
#[derive(Debug, Clone)]
pub struct SchemaEntry {
pub key: &'static str,
pub option_type: OptionType,
pub description: &'static str,
pub category: Category,
pub dependencies: &'static [&'static str],
pub conflicts_with: &'static [&'static str],
pub gpu_vendor_only: GpuVendor,
pub gamescope_only: bool,
}
/// Validation result for a single option.
#[derive(Debug, Clone, PartialEq)]
pub enum ValidationResult {
Ok,
Warning(String),
Error(String),
}
/// The full in-memory representation of a parsed config file.
#[derive(Debug, Clone)]
pub struct AnnotatedConfig {
/// Ordered list of lines as they appear in the file.
pub lines: Vec<ConfigLine>,
/// Fast lookup map: key → (line_index, current_value).
pub options: indexmap::IndexMap<String, (usize, ConfigValue)>,
/// Source path, if backed by a file.
pub path: Option<PathBuf>,
/// Whether this config has unsaved in-memory changes.
pub dirty: bool,
}