config: add fallback output mode
This commit is contained in:
parent
a975e3b25a
commit
dd3f8bad40
16 changed files with 215 additions and 19 deletions
38
toml-config/src/config/parsers/fallback_output_mode.rs
Normal file
38
toml-config/src/config/parsers/fallback_output_mode.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use {
|
||||
crate::{
|
||||
config::parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
toml::toml_span::{Span, SpannedExt},
|
||||
},
|
||||
jay_config::input::FallbackOutputMode,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct FallbackOutputModeParser;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FallbackOutputModeParserError {
|
||||
#[error(transparent)]
|
||||
DataType(#[from] UnexpectedDataType),
|
||||
#[error("Unknown mode {0}")]
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
impl Parser for FallbackOutputModeParser {
|
||||
type Value = FallbackOutputMode;
|
||||
type Error = FallbackOutputModeParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::String];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
use FallbackOutputMode::*;
|
||||
let api = match string.to_ascii_lowercase().as_str() {
|
||||
"cursor" => Cursor,
|
||||
"focus" => Focus,
|
||||
_ => {
|
||||
return Err(
|
||||
FallbackOutputModeParserError::Unknown(string.to_string()).spanned(span)
|
||||
);
|
||||
}
|
||||
};
|
||||
Ok(api)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue