Add clap dependency and update app for CLI integration
Update Cargo files to add clap and related dependencies, restructure App to handle configuration from CLI, and update nix module to support config source tracking. Add new cli module and adjust main to initialize modules at startup.
This commit is contained in:
77
src/main.rs
77
src/main.rs
@@ -1,22 +1,25 @@
|
||||
use garandos_tui::{
|
||||
app::{App, Event, handle_input_events, run_background_thread},
|
||||
// nix::{collect_nix_options, get_nix_value_by_path, toggle_bool_at_path},
|
||||
app::{App, Event, handle_input_events},
|
||||
cli::{NixModules, get_modules},
|
||||
nix::ConfigSource,
|
||||
};
|
||||
use ratatui::{Terminal, prelude::CrosstermBackend, style::Color};
|
||||
// use rnix::{Parse, Root, SyntaxNode};
|
||||
// use std::fs;
|
||||
use ratatui::{Terminal, prelude::CrosstermBackend};
|
||||
use std::{
|
||||
io,
|
||||
io::{Result, Stdout},
|
||||
sync::mpsc::{self, Sender},
|
||||
thread,
|
||||
};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let mut terminal: Terminal<CrosstermBackend<io::Stdout>> = ratatui::init();
|
||||
fn main() -> Result<()> {
|
||||
let nix_modules: NixModules = get_modules();
|
||||
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
|
||||
let mut app: App = App {
|
||||
exit: false,
|
||||
progress_bar_color: Color::Green,
|
||||
background_progress: 0_f64,
|
||||
system_modules: nix_modules.system_modules,
|
||||
home_modules: nix_modules.home_modules,
|
||||
current_file: ConfigSource::System,
|
||||
selected_index: 0_usize,
|
||||
last_action_status: "".to_string(),
|
||||
};
|
||||
|
||||
let (event_tx, event_rx) = mpsc::channel::<Event>();
|
||||
@@ -26,56 +29,12 @@ fn main() -> io::Result<()> {
|
||||
handle_input_events(tx_to_input_events);
|
||||
});
|
||||
|
||||
let tx_to_background_events: Sender<Event> = event_tx.clone();
|
||||
thread::spawn(move || {
|
||||
run_background_thread(tx_to_background_events);
|
||||
});
|
||||
|
||||
let app_result: Result<(), io::Error> = app.run(&mut terminal, event_rx);
|
||||
// let tx_to_file_edit_events: Sender<Event> = event_tx.clone();
|
||||
// thread::spawn(move || {
|
||||
// // handle_file_edit_events(tx_to_file_edit_events);
|
||||
// });
|
||||
|
||||
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
||||
ratatui::restore();
|
||||
app_result
|
||||
}
|
||||
|
||||
// fn main() {
|
||||
// let content: String =
|
||||
// fs::read_to_string("src/test.nix").expect("Nie można odczytać pliku src/test.nix");
|
||||
|
||||
// let ast: Parse<Root> = Root::parse(&content);
|
||||
|
||||
// if !ast.errors().is_empty() {
|
||||
// eprintln!("Błędy parsowania:");
|
||||
// for error in ast.errors() {
|
||||
// eprintln!(" - {}", error);
|
||||
// }
|
||||
// eprintln!();
|
||||
// }
|
||||
|
||||
// let node: SyntaxNode = ast.syntax();
|
||||
// let options: Vec<(String, String, bool)> = collect_nix_options(&node);
|
||||
|
||||
// const OPTION: &str = "flatpak.enable";
|
||||
|
||||
// println!("Options:");
|
||||
// for (_, path, value) in options {
|
||||
// if path == OPTION {
|
||||
// println!("{} = {};", path, value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // if let Some(value) = get_nix_value_by_path(&node, OPTION) {
|
||||
// // println!("Flatseal ma wartość: {}", value);
|
||||
// // }
|
||||
|
||||
// let new_node: SyntaxNode = toggle_bool_at_path(&node, OPTION);
|
||||
// let new_options: Vec<(String, String, bool)> = collect_nix_options(&new_node);
|
||||
|
||||
// println!("\nNew Options:");
|
||||
// for (_, path, value) in new_options {
|
||||
// if path == OPTION {
|
||||
// println!("{} = {};", path, value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// fs::write("src/test.nix", new_node.to_string()).expect("Nie można zapisać tego pliku");
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user