use ratatui::backend::CrosstermBackend; use ratatui::Terminal; use std::io; use std::path::PathBuf; use structopt::StructOpt; use musichoard::{ collection::MhCollectionManager, database::json::{JsonDatabase, JsonDatabaseFileBackend}, library::beets::{BeetsLibrary, BeetsLibraryCommandExecutor}, }; mod tui; use tui::{ app::TuiApp, event::EventChannel, handler::TuiEventHandler, listener::TuiEventListener, ui::Ui, Tui, }; #[derive(StructOpt)] struct Opt { #[structopt( short = "b", long = "beets", name = "beets config file path", parse(from_os_str) )] beets_config_file_path: Option, #[structopt( short = "d", long = "database", name = "database file path", default_value = "database.json", parse(from_os_str) )] database_file_path: PathBuf, } fn main() { // Create the application. let opt = Opt::from_args(); let beets = BeetsLibrary::new( BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref()), ); let database = JsonDatabase::new(JsonDatabaseFileBackend::new(&opt.database_file_path)); let collection_manager = MhCollectionManager::new(beets, database); // Initialize the terminal user interface. let backend = CrosstermBackend::new(io::stdout()); let terminal = Terminal::new(backend).expect("failed to initialise terminal"); let channel = EventChannel::new(); let listener = TuiEventListener::new(channel.sender()); let handler = TuiEventHandler::new(channel.receiver()); let ui = Ui::new(); let app = TuiApp::new(collection_manager).expect("failed to initialise app"); // Run the TUI application. Tui::run(terminal, app, ui, handler, listener).expect("failed to run tui"); } #[cfg(test)] #[macro_use] mod testlib; #[cfg(test)] mod tests { use mockall::mock; use once_cell::sync::Lazy; use musichoard::collection::{self, Collection, CollectionManager}; use musichoard::*; pub static COLLECTION: Lazy> = Lazy::new(|| collection!()); mock! { pub CollectionManager {} impl CollectionManager for CollectionManager { fn rescan_library(&mut self) -> Result<(), collection::Error>; fn save_to_database(&mut self) -> Result<(), collection::Error>; fn get_collection(&self) -> &Collection; } } }