gostui-setup #1

Merged
GarandPLG merged 9 commits from gostui-setup into main 2025-12-06 22:09:37 +00:00
Showing only changes of commit 09faba4f7c - Show all commits

View File

@@ -33,7 +33,6 @@ pub struct App {
pub enum Event {
Input(KeyEvent),
// EditFile,
}
impl App {
@@ -45,8 +44,6 @@ impl App {
};
match event {
Event::Input(key_event) => self.handle_key_event(key_event)?,
// Event::EditFile => self.handle_file_edit_events()?,
// _ => {}
}
terminal.draw(|frame: &mut Frame<'_>| self.draw(frame))?;
}
@@ -81,28 +78,8 @@ impl App {
}
// ENTER - zmień wartość boolen danej opcji
else if key_event.kind == KeyEventKind::Press && key_event.code == KeyCode::Enter {
let modules: &Vec<ConfigOption> = match self.current_file {
ConfigSource::System => &self.system_modules.clone(),
ConfigSource::Home => &self.home_modules.clone(),
};
let node: &SyntaxNode = match self.current_file {
ConfigSource::System => &self.system_ast.syntax(),
ConfigSource::Home => &self.home_ast.syntax(),
};
if let Some(module) = modules.get(self.selected_index) {
let new_node: SyntaxNode = toggle_bool_at_path(node, module.path.as_str());
let new_ast: Parse<Root> = Root::parse(&new_node.to_string().as_str());
let new_modules: Vec<ConfigOption> =
collect_nix_options(&new_node, "", self.current_file.clone());
let new_module_value: bool =
if let Some(value) = get_nix_value_by_path(&new_node, module.path.as_str()) {
value
} else {
module.value.clone()
};
let (modules, new_node, new_ast, new_modules, new_module_value) =
self.get_selected_option_context();
self.last_action_status = if let Some(module) = modules.get(self.selected_index) {
match self.current_file {
@@ -129,10 +106,64 @@ impl App {
"Nothing changed".to_string()
};
}
}
Ok(())
}
fn get_selected_option_context(
&self,
) -> (
Vec<ConfigOption>,
SyntaxNode,
Parse<Root>,
Vec<ConfigOption>,
bool,
) {
let modules: &Vec<ConfigOption> = match self.current_file {
ConfigSource::System => &self.system_modules,
ConfigSource::Home => &self.home_modules,
};
let node: &SyntaxNode = match self.current_file {
ConfigSource::System => &self.system_ast.syntax(),
ConfigSource::Home => &self.home_ast.syntax(),
};
let fallback_module_value: bool = modules
.get(self.selected_index)
.map(|m| m.value.clone())
.unwrap_or(false);
let (new_node, new_ast, new_modules, new_module_value) = match modules
.get(self.selected_index)
{
Some(module) => {
let new_node: SyntaxNode = toggle_bool_at_path(node, module.path.as_str());
let new_ast: Parse<Root> = Root::parse(&new_node.to_string().as_str());
let new_modules: Vec<ConfigOption> =
collect_nix_options(&new_node, "", self.current_file.clone());
let new_module_value: bool = get_nix_value_by_path(&new_node, module.path.as_str())
.unwrap_or_else(|| module.value.clone());
(new_node, new_ast, new_modules, new_module_value)
}
None => (
node.clone(),
Root::parse(&node.to_string().as_str()),
Vec::new(),
fallback_module_value,
),
};
(
modules.to_vec(),
new_node,
new_ast,
new_modules,
new_module_value,
)
}
}
impl Widget for &App {