Skip to content

Commit 946c95a

Browse files
committed
refactor!: use mod.rs to clean up directory structure...
Additionally, `lore` was removed as public API. The discusison for this can be found in kworkflow#128. And imports (of modules, external crates and std create) now follow the recommended order. 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. Signed-off-by: Ivin Joel Abraham <[email protected]>
1 parent ba9f399 commit 946c95a

28 files changed

+190
-157
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: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
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+
112
use crate::{
13+
infrastructure::{garbage_collector, logging::Logger},
214
log_on_error,
15+
lore::{
16+
lore_api_client::BlockingLoreAPIClient,
17+
lore_session,
18+
patch::{Author, Patch},
19+
},
320
ui::popup::{info_popup::InfoPopUp, PopUp},
421
};
5-
use ansi_to_tui::IntoText;
6-
use color_eyre::eyre::bail;
22+
723
use config::Config;
824
use cover_renderer::render_cover;
9-
use logging::Logger;
10-
use patch_hub::lore::{
11-
lore_api_client::BlockingLoreAPIClient,
12-
lore_session,
13-
patch::{Author, Patch},
14-
};
1525
use patch_renderer::{render_patch_preview, PatchRenderer};
16-
use ratatui::text::Text;
1726
use screens::{
1827
bookmarked::BookmarkedPatchsets,
1928
details_actions::{DetailsActions, PatchsetAction},
@@ -22,15 +31,6 @@ use screens::{
2231
mail_list::MailingListSelection,
2332
CurrentScreen,
2433
};
25-
use std::collections::{HashMap, HashSet};
26-
27-
use crate::utils;
28-
29-
mod config;
30-
pub mod cover_renderer;
31-
pub mod logging;
32-
pub mod patch_renderer;
33-
pub mod screens;
3434

3535
/// Type that represents the overall state of the application. It can be viewed
3636
/// as the **Model** component of `patch-hub`.
@@ -85,7 +85,7 @@ impl App {
8585
// Initialize the logger before the app starts
8686
Logger::init_log_file(&config)?;
8787
Logger::info("patch-hub started");
88-
logging::garbage_collector::collect_garbage(&config);
88+
garbage_collector::collect_garbage(&config);
8989

9090
Ok(App {
9191
current_screen: CurrentScreen::MailingListSelection,
@@ -394,30 +394,30 @@ impl App {
394394
pub fn check_external_deps(&self) -> bool {
395395
let mut app_can_run = true;
396396

397-
if !utils::binary_exists("b4") {
397+
if which::which("b4").is_err() {
398398
Logger::error("b4 is not installed, patchsets cannot be downloaded");
399399
app_can_run = false;
400400
}
401401

402-
if !utils::binary_exists("git") {
402+
if which::which("git").is_err() {
403403
Logger::warn("git is not installed, send-email won't work");
404404
}
405405

406406
match self.config.patch_renderer() {
407407
PatchRenderer::Bat => {
408-
if !utils::binary_exists("bat") {
408+
if which::which("bat").is_err() {
409409
Logger::warn("bat is not installed, patch rendering will fallback to default");
410410
}
411411
}
412412
PatchRenderer::Delta => {
413-
if !utils::binary_exists("delta") {
413+
if which::which("delta").is_err() {
414414
Logger::warn(
415415
"delta is not installed, patch rendering will fallback to default",
416416
);
417417
}
418418
}
419419
PatchRenderer::DiffSoFancy => {
420-
if !utils::binary_exists("diff-so-fancy") {
420+
if which::which("diff-so-fancy").is_err() {
421421
Logger::warn(
422422
"diff-so-fancy is not installed, patch rendering will fallback to default",
423423
);

src/app/screens/bookmarked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use patch_hub::lore::patch::Patch;
1+
use crate::lore::patch::Patch;
22

33
pub struct BookmarkedPatchsets {
44
pub bookmarked_patchsets: Vec<Patch>,

src/app/screens/details_actions.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
use crate::app::config::{Config, KernelTree};
2-
3-
use super::CurrentScreen;
4-
use ::patch_hub::lore::{lore_api_client::BlockingLoreAPIClient, lore_session, patch::Patch};
51
use color_eyre::eyre::{bail, eyre};
6-
use patch_hub::lore::patch::Author;
72
use ratatui::text::Text;
3+
84
use std::{
95
collections::{HashMap, HashSet},
106
path::Path,
117
process::Command,
128
};
139

10+
use crate::{
11+
app::config::{Config, KernelTree},
12+
lore::{
13+
lore_api_client::BlockingLoreAPIClient,
14+
lore_session,
15+
patch::{Author, Patch},
16+
},
17+
};
18+
19+
use super::CurrentScreen;
20+
1421
pub struct DetailsActions {
1522
pub representative_patch: Patch,
1623
/// Raw patches as plain text files

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/app/screens/latest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use color_eyre::eyre::bail;
22
use derive_getters::Getters;
3-
use patch_hub::lore::{
3+
4+
use crate::lore::{
45
lore_api_client::{BlockingLoreAPIClient, ClientError},
56
lore_session::{LoreSession, LoreSessionError},
67
patch::Patch,

src/app/screens/mail_list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use color_eyre::eyre::bail;
2-
use patch_hub::lore::{
2+
3+
use crate::lore::{
34
lore_api_client::BlockingLoreAPIClient, lore_session, mailing_list::MailingList,
45
};
56

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,

0 commit comments

Comments
 (0)