1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! main menu stuff
use {
super::Handlers,
crate::{
config::instance::reload_config,
error::Result,
ui::menus::{
ConfigMenu, MainMenu, blacklist::BlacklistMenu, explore::ExploreMenu,
reorganize::RegorganizeMenu, view::ViewMenu,
},
},
miette::IntoDiagnostic,
};
impl Handlers {
/// run the main loop
///
/// [`MainMenu::ManageBlacklist`] runs the blacklist manager
/// [`MainMenu::EditConfig`] lets the user edit their config file
/// [`MainMenu::ViewLatest`] displays the latest uploads on e621
/// [`MainMenu::OpenInBrowser`] opens the downloads gallery in the users browser
/// [`MainMenu::Reorganize`] runs the downloads reorganizer
/// [`MainMenu::ExploreDownloads`] runs the downloads explorer
/// [`MainMenu::UpdateDownloads`] runs the downloads updater
/// [`MainMenu::Search`] runs the search menu (see [`crate::app::handlers::search`])
/// [`MainMenu::ReloadConfig`] reloads and reapplies the config file
/// [`MainMenu::Exit`] exits e62rs
///
/// # Errors
///
/// returns an error if it fails to get the user selection in the main menu
/// returns an error if it fails to run the logic associated with the user selection
pub async fn run_main_loop(&self) -> Result<()> {
'main: loop {
let selection = match MainMenu::select("What would you like to do?").ask() {
Ok(sel) => sel,
Err(_) if self.was_interrupted() => continue 'main,
Err(e) => return Err(e.into()),
};
match selection.value {
MainMenu::ManageBlacklist => self.ui.manage_blacklist().await.into_diagnostic()?,
MainMenu::ViewLatest => self.ui.display_latest_posts().await.into_diagnostic()?,
MainMenu::OpenInBrowser => self.ui.serve_downloads().await.into_diagnostic()?,
MainMenu::Reorganize => self.ui.reorganize_downloads().await.into_diagnostic()?,
MainMenu::ExploreDownloads => {
self.ui.explore_downloads().await.into_diagnostic()?
}
MainMenu::UpdateDownloads => {
self.ui.redownload_by_artists().await.into_diagnostic()?
}
MainMenu::Search => self.handle_search().await?,
MainMenu::ManageConfig => {
match ConfigMenu::select("What would you like to do?").ask() {
Ok(sel) => match sel.value {
ConfigMenu::Edit => {
self.ui.edit_config_file().await.into_diagnostic()?
}
ConfigMenu::Reload => reload_config()?,
ConfigMenu::Back => continue 'main,
},
Err(_) if self.was_interrupted() => continue 'main,
Err(e) => return Err(e.into()),
}
}
MainMenu::Exit => break 'main,
}
}
Ok(())
}
}