summaryrefslogtreecommitdiffstats
path: root/src/config/config_type.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/config_type.rs')
-rw-r--r--src/config/config_type.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/config/config_type.rs b/src/config/config_type.rs
new file mode 100644
index 0000000..7a4755a
--- /dev/null
+++ b/src/config/config_type.rs
@@ -0,0 +1,75 @@
+#[derive(Copy, Clone, Debug)]
+pub enum ConfigType {
+ App,
+ Mimetype,
+ Keymap,
+ Theme,
+ Preview,
+ Bookmarks,
+ Icons,
+}
+
+impl std::fmt::Display for ConfigType {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(self.as_str())
+ }
+}
+
+impl clap::ValueEnum for ConfigType {
+ fn value_variants<'a>() -> &'a [Self] {
+ Self::enumerate()
+ }
+
+ fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
+ Some(clap::builder::PossibleValue::new(self.as_str()))
+ }
+}
+
+impl ConfigType {
+ pub const fn enumerate() -> &'static [Self] {
+ &[
+ Self::App,
+ Self::Mimetype,
+ Self::Keymap,
+ Self::Theme,
+ Self::Preview,
+ Self::Bookmarks,
+ Self::Icons,
+ ]
+ }
+
+ pub const fn as_str(&self) -> &'static str {
+ match self {
+ Self::App => "joshuto",
+ Self::Mimetype => "mimetype",
+ Self::Keymap => "keymap",
+ Self::Theme => "theme",
+ Self::Preview => "preview",
+ Self::Bookmarks => "bookmarks",
+ Self::Icons => "icons",
+ }
+ }
+
+ pub const fn as_filename(&self) -> &'static str {
+ match self {
+ Self::App => "joshuto.toml",
+ Self::Mimetype => "mimetype.toml",
+ Self::Keymap => "keymap.toml",
+ Self::Theme => "theme.toml",
+ Self::Preview => "preview.toml",
+ Self::Bookmarks => "bookmarks.toml",
+ Self::Icons => "icons.toml",
+ }
+ }
+
+ pub const fn embedded_config(&self) -> Option<&'static str> {
+ use super::clean;
+ match self {
+ Self::App => Some(clean::app::DEFAULT_CONFIG_FILE_PATH),
+ Self::Keymap => Some(clean::keymap::DEFAULT_CONFIG_FILE_PATH),
+ Self::Theme => Some(clean::theme::DEFAULT_CONFIG_FILE_PATH),
+ Self::Icons => Some(clean::icon::DEFAULT_CONFIG_FILE_PATH),
+ Self::Mimetype | Self::Preview | Self::Bookmarks => None,
+ }
+ }
+}