config: allow configuring the simple IM
This commit is contained in:
parent
58b9830aaa
commit
2f22a61710
15 changed files with 367 additions and 7 deletions
|
|
@ -39,6 +39,7 @@ mod output;
|
|||
mod output_match;
|
||||
mod repeat_rate;
|
||||
pub mod shortcuts;
|
||||
mod simple_im;
|
||||
mod status;
|
||||
mod tearing;
|
||||
mod theme;
|
||||
|
|
|
|||
|
|
@ -155,6 +155,10 @@ impl ActionParser<'_> {
|
|||
"jump-to-mark" => JumpToMark,
|
||||
"clear-modes" => PopMode(false),
|
||||
"pop-mode" => PopMode(true),
|
||||
"enable-simple-im" => EnableSimpleIm(true),
|
||||
"disable-simple-im" => EnableSimpleIm(false),
|
||||
"toggle-simple-im-enabled" => ToggleSimpleImEnabled,
|
||||
"reload-simple-im" => ReloadSimpleIm,
|
||||
_ => {
|
||||
return Err(
|
||||
ActionParserError::UnknownSimpleAction(string.to_string()).spanned(span)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use {
|
|||
ComplexShortcutsParser, ShortcutsParser, ShortcutsParserError,
|
||||
parse_modified_keysym_str,
|
||||
},
|
||||
simple_im::SimpleImParser,
|
||||
status::StatusParser,
|
||||
tearing::TearingParser,
|
||||
theme::ThemeParser,
|
||||
|
|
@ -139,7 +140,13 @@ impl Parser for ConfigParser<'_> {
|
|||
show_bar,
|
||||
focus_history_val,
|
||||
),
|
||||
(middle_click_paste, input_modes_val, workspace_display_order_val, auto_reload),
|
||||
(
|
||||
middle_click_paste,
|
||||
input_modes_val,
|
||||
workspace_display_order_val,
|
||||
auto_reload,
|
||||
simple_im_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
opt(val("keymap")),
|
||||
|
|
@ -194,6 +201,7 @@ impl Parser for ConfigParser<'_> {
|
|||
opt(val("modes")),
|
||||
opt(val("workspace-display-order")),
|
||||
recover(opt(bol("auto-reload"))),
|
||||
opt(val("simple-im")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -505,6 +513,15 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut simple_im = None;
|
||||
if let Some(value) = simple_im_val {
|
||||
match value.parse(&mut SimpleImParser(self.0)) {
|
||||
Ok(v) => simple_im = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse simple IM setting: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
|
|
@ -549,6 +566,7 @@ impl Parser for ConfigParser<'_> {
|
|||
middle_click_paste: middle_click_paste.despan(),
|
||||
input_modes,
|
||||
workspace_display_order,
|
||||
simple_im,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
toml-config/src/config/parsers/simple_im.rs
Normal file
44
toml-config/src/config/parsers/simple_im.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
SimpleIm,
|
||||
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 SimpleImParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extract(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
pub struct SimpleImParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for SimpleImParser<'_> {
|
||||
type Value = SimpleIm;
|
||||
type Error = SimpleImParserError;
|
||||
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 (enabled,) = ext.extract((recover(opt(bol("enabled"))),))?;
|
||||
Ok(SimpleIm {
|
||||
enabled: enabled.despan(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue