Skip to content

Commit 71fb824

Browse files
committed
refactor!: use mod.rs to clean up directory structure
Using `mod.rs` allows for a cleaner directory as we can avoid having a file for each module in the root directory. This makes it easier to identify the important files and represents the compartmentalization of the code better. Additionally, imports (of modules, external crates and std create) in files now follow the recommended order. Signed-off-by: Ivin Joel Abraham <[email protected]>
1 parent 6f24aa7 commit 71fb824

File tree

19 files changed

+93
-74
lines changed

19 files changed

+93
-74
lines changed

src/app/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use derive_getters::Getters;
22
use serde::{Deserialize, Serialize};
3+
34
use std::{
45
collections::{HashMap, HashSet},
56
env,

src/app.rs renamed to src/app/mod.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
use crate::infrastructure::logging::Logger;
2-
use crate::lore::{
3-
lore_api_client::BlockingLoreAPIClient,
4-
lore_session,
5-
patch::{Author, Patch},
6-
};
1+
pub mod config;
2+
mod cover_renderer;
3+
mod patch_renderer;
4+
pub mod screens;
5+
6+
use ansi_to_tui::IntoText;
7+
use color_eyre::eyre::bail;
8+
use ratatui::text::Text;
9+
10+
use std::collections::{HashMap, HashSet};
11+
712
use crate::{
8-
infrastructure::logging,
13+
infrastructure::{garbage_collector, logging::Logger},
914
log_on_error,
15+
lore::{
16+
lore_api_client::BlockingLoreAPIClient,
17+
lore_session,
18+
patch::{Author, Patch},
19+
},
1020
ui::popup::{info_popup::InfoPopUp, PopUp},
1121
};
12-
use ansi_to_tui::IntoText;
13-
use color_eyre::eyre::bail;
22+
1423
use config::Config;
1524
use cover_renderer::render_cover;
1625
use patch_renderer::{render_patch_preview, PatchRenderer};
17-
use ratatui::text::Text;
1826
use screens::{
1927
bookmarked::BookmarkedPatchsets,
2028
details_actions::{DetailsActions, PatchsetAction},
@@ -23,12 +31,6 @@ use screens::{
2331
mail_list::MailingListSelection,
2432
CurrentScreen,
2533
};
26-
use std::collections::{HashMap, HashSet};
27-
28-
pub mod config;
29-
pub mod cover_renderer;
30-
pub mod patch_renderer;
31-
pub mod screens;
3234

3335
/// Type that represents the overall state of the application. It can be viewed
3436
/// as the **Model** component of `patch-hub`.
@@ -80,7 +82,7 @@ impl App {
8082
// Initialize the logger before the app starts
8183
Logger::init_log_file(&config)?;
8284
Logger::info("patch-hub started");
83-
logging::garbage_collector::collect_garbage(&config);
85+
garbage_collector::collect_garbage(&config);
8486

8587
Ok(App {
8688
current_screen: CurrentScreen::MailingListSelection,

src/app/screens/edit_config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use color_eyre::eyre::bail;
2+
use derive_getters::Getters;
3+
14
use std::{collections::HashMap, fmt::Display, path::Path};
25

36
use crate::app::config::Config;
4-
use color_eyre::eyre::bail;
5-
use derive_getters::Getters;
67

78
#[derive(Debug, Getters)]
89
pub struct EditConfig {

src/handler/bookmarked.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
use ratatui::{
2+
crossterm::event::{KeyCode, KeyEvent},
3+
prelude::Backend,
4+
Terminal,
5+
};
6+
17
use std::ops::ControlFlow;
28

39
use crate::{
410
app::{screens::CurrentScreen, App},
511
loading_screen,
612
ui::popup::{help::HelpPopUpBuilder, PopUp},
713
};
8-
use ratatui::{
9-
crossterm::event::{KeyCode, KeyEvent},
10-
prelude::Backend,
11-
Terminal,
12-
};
1314

1415
pub fn handle_bookmarked_patchsets<B>(
1516
app: &mut App,

src/handler/edit_config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use ratatui::crossterm::event::{KeyCode, KeyEvent};
2+
13
use crate::{
24
app::{screens::CurrentScreen, App},
35
ui::popup::{help::HelpPopUpBuilder, PopUp},
46
};
5-
use ratatui::crossterm::event::{KeyCode, KeyEvent};
67

78
pub fn handle_edit_config(app: &mut App, key: KeyEvent) -> color_eyre::Result<()> {
89
if let Some(edit_config_state) = app.edit_config.as_mut() {

src/handler/latest.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
use ratatui::{
2+
crossterm::event::{KeyCode, KeyEvent},
3+
prelude::Backend,
4+
Terminal,
5+
};
6+
17
use std::ops::ControlFlow;
28

39
use crate::{
410
app::{screens::CurrentScreen, App},
511
loading_screen,
612
ui::popup::{help::HelpPopUpBuilder, PopUp},
713
};
8-
use ratatui::{
9-
crossterm::event::{KeyCode, KeyEvent},
10-
prelude::Backend,
11-
Terminal,
12-
};
1314

1415
pub fn handle_latest_patchsets<B>(
1516
app: &mut App,

src/handler/mail_list.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
use ratatui::{
2+
crossterm::event::{KeyCode, KeyEvent},
3+
prelude::Backend,
4+
Terminal,
5+
};
6+
17
use std::ops::ControlFlow;
28

39
use crate::{
410
app::{screens::CurrentScreen, App},
511
loading_screen,
612
ui::popup::{help::HelpPopUpBuilder, PopUp},
713
};
8-
use ratatui::{
9-
crossterm::event::{KeyCode, KeyEvent},
10-
prelude::Backend,
11-
Terminal,
12-
};
1314

1415
pub fn handle_mailing_list_selection<B>(
1516
app: &mut App,

src/handler.rs renamed to src/handler/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
pub mod bookmarked;
2-
pub mod details_actions;
3-
pub mod edit_config;
4-
pub mod latest;
5-
pub mod mail_list;
1+
mod bookmarked;
2+
mod details_actions;
3+
mod edit_config;
4+
mod latest;
5+
mod mail_list;
6+
7+
use ratatui::{
8+
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind},
9+
prelude::Backend,
10+
Terminal,
11+
};
612

713
use std::{
814
ops::ControlFlow,
915
time::{Duration, Instant},
1016
};
1117

1218
use crate::{
13-
app::screens::CurrentScreen, infrastructure::logging::Logger, loading_screen, ui::draw_ui, App,
19+
app::{screens::CurrentScreen, App},
20+
infrastructure::logging::Logger,
21+
loading_screen,
22+
ui::draw_ui,
1423
};
1524

1625
use bookmarked::handle_bookmarked_patchsets;
@@ -19,11 +28,6 @@ use details_actions::handle_patchset_details;
1928
use edit_config::handle_edit_config;
2029
use latest::handle_latest_patchsets;
2130
use mail_list::handle_mailing_list_selection;
22-
use ratatui::{
23-
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind},
24-
prelude::Backend,
25-
Terminal,
26-
};
2731

2832
fn key_handling<B>(
2933
mut terminal: Terminal<B>,

src/infrastructure/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pub mod errors;
22
pub mod logging;
33
pub mod terminal;
4+
5+
pub use logging::garbage_collector;

src/lore/lore_api_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::time::Duration;
2-
31
use mockall::automock;
42
use thiserror::Error;
53
use ureq::tls::TlsConfig;
64
use ureq::Agent;
75

6+
use std::time::Duration;
7+
88
#[cfg(test)]
99
mod tests;
1010

0 commit comments

Comments
 (0)