2021-03-15 10:40:52 +00:00
|
|
|
use crate::config::{ModuleConfig, VecOr};
|
2020-04-11 16:37:24 +00:00
|
|
|
|
|
|
|
use starship_module_config_derive::ModuleConfig;
|
|
|
|
|
|
|
|
#[derive(Clone, Default, PartialEq)]
|
|
|
|
pub struct Files<'a>(pub Vec<&'a str>);
|
|
|
|
|
|
|
|
#[derive(Clone, Default, PartialEq)]
|
|
|
|
pub struct Extensions<'a>(pub Vec<&'a str>);
|
|
|
|
|
|
|
|
#[derive(Clone, Default, PartialEq)]
|
|
|
|
pub struct Directories<'a>(pub Vec<&'a str>);
|
|
|
|
|
|
|
|
#[derive(Clone, ModuleConfig)]
|
|
|
|
pub struct CustomConfig<'a> {
|
2020-07-07 22:45:32 +00:00
|
|
|
pub format: &'a str,
|
|
|
|
pub symbol: &'a str,
|
2020-04-11 16:37:24 +00:00
|
|
|
pub command: &'a str,
|
|
|
|
pub when: Option<&'a str>,
|
2020-05-27 07:38:05 +00:00
|
|
|
pub shell: VecOr<&'a str>,
|
2020-04-11 16:37:24 +00:00
|
|
|
pub description: &'a str,
|
2020-07-07 22:45:32 +00:00
|
|
|
pub style: &'a str,
|
2020-04-11 16:37:24 +00:00
|
|
|
pub disabled: bool,
|
|
|
|
pub files: Files<'a>,
|
|
|
|
pub extensions: Extensions<'a>,
|
|
|
|
pub directories: Directories<'a>,
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:40:52 +00:00
|
|
|
impl<'a> Default for CustomConfig<'a> {
|
|
|
|
fn default() -> Self {
|
2020-04-11 16:37:24 +00:00
|
|
|
CustomConfig {
|
2021-01-20 18:01:49 +00:00
|
|
|
format: "[$symbol($output )]($style)",
|
2020-07-07 22:45:32 +00:00
|
|
|
symbol: "",
|
2020-04-11 16:37:24 +00:00
|
|
|
command: "",
|
|
|
|
when: None,
|
2020-05-27 07:38:05 +00:00
|
|
|
shell: VecOr::default(),
|
2020-04-11 16:37:24 +00:00
|
|
|
description: "<custom config>",
|
2020-07-07 22:45:32 +00:00
|
|
|
style: "green bold",
|
2020-04-11 16:37:24 +00:00
|
|
|
disabled: false,
|
|
|
|
files: Files::default(),
|
|
|
|
extensions: Extensions::default(),
|
|
|
|
directories: Directories::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ModuleConfig<'a> for Files<'a> {
|
|
|
|
fn from_config(config: &'a toml::Value) -> Option<Self> {
|
|
|
|
let mut files = Vec::new();
|
|
|
|
|
|
|
|
for item in config.as_array()? {
|
|
|
|
if let Some(file) = item.as_str() {
|
|
|
|
files.push(file);
|
|
|
|
} else {
|
2020-09-28 20:38:50 +00:00
|
|
|
log::warn!("Unexpected file {:?}", item);
|
2020-04-11 16:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Files(files))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ModuleConfig<'a> for Extensions<'a> {
|
|
|
|
fn from_config(config: &'a toml::Value) -> Option<Self> {
|
|
|
|
let mut extensions = Vec::new();
|
|
|
|
|
|
|
|
for item in config.as_array()? {
|
|
|
|
if let Some(file) = item.as_str() {
|
|
|
|
extensions.push(file);
|
|
|
|
} else {
|
2020-09-28 20:38:50 +00:00
|
|
|
log::warn!("Unexpected extension {:?}", item);
|
2020-04-11 16:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Extensions(extensions))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ModuleConfig<'a> for Directories<'a> {
|
|
|
|
fn from_config(config: &'a toml::Value) -> Option<Self> {
|
|
|
|
let mut directories = Vec::new();
|
|
|
|
|
|
|
|
for item in config.as_array()? {
|
|
|
|
if let Some(file) = item.as_str() {
|
|
|
|
directories.push(file);
|
|
|
|
} else {
|
2020-09-28 20:38:50 +00:00
|
|
|
log::warn!("Unexpected directory {:?}", item);
|
2020-04-11 16:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Directories(directories))
|
|
|
|
}
|
|
|
|
}
|