1
0
Fork 0
forked from wry/wry

seat: add focus history

This commit is contained in:
Julian Orth 2025-07-18 20:09:34 +02:00
parent 9941263a82
commit d12234b38b
21 changed files with 546 additions and 22 deletions

View file

@ -0,0 +1,53 @@
use {
crate::{
config::{
context::Context,
extractor::{Extractor, ExtractorError, bol, opt, recover},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
},
toml::{
toml_span::{DespanExt, Span, Spanned},
toml_value::Value,
},
},
indexmap::IndexMap,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum FocusHistoryParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct FocusHistoryParser<'a>(pub &'a Context<'a>);
#[derive(Debug, Clone)]
pub struct FocusHistory {
pub only_visible: Option<bool>,
pub same_workspace: Option<bool>,
}
impl Parser for FocusHistoryParser<'_> {
type Value = FocusHistory;
type Error = FocusHistoryParserError;
const EXPECTED: &'static [DataType] = &[DataType::Table];
fn parse_table(
&mut self,
span: Span,
table: &IndexMap<Spanned<String>, Spanned<Value>>,
) -> ParseResult<Self> {
let mut ext = Extractor::new(self.0, span, table);
let (only_visible, same_workspace) = ext.extract((
recover(opt(bol("only-visible"))),
recover(opt(bol("same-workspace"))),
))?;
Ok(FocusHistory {
only_visible: only_visible.despan(),
same_workspace: same_workspace.despan(),
})
}
}