1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-15 09:44:22 +00:00
starship/src/configs/custom.rs

94 lines
2.5 KiB
Rust
Raw Normal View History

use crate::config::{ModuleConfig, RootModuleConfig, 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> {
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>,
pub shell: VecOr<&'a str>,
2020-04-11 16:37:24 +00:00
pub description: &'a str,
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>,
}
impl<'a> RootModuleConfig<'a> for CustomConfig<'a> {
fn new() -> Self {
CustomConfig {
format: "[$symbol$output]($style) ",
symbol: "",
2020-04-11 16:37:24 +00:00
command: "",
when: None,
shell: VecOr::default(),
2020-04-11 16:37:24 +00:00
description: "<custom config>",
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 {
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 {
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 {
log::warn!("Unexpected directory {:?}", item);
2020-04-11 16:37:24 +00:00
}
}
Some(Directories(directories))
}
}