Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use derive_getters::Getters;
use proc_macros::serde_individual_default;
use serde::{Deserialize, Serialize};

use std::{
collections::{HashMap, HashSet},
env,
Expand Down
6 changes: 3 additions & 3 deletions src/app/cover_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use serde::{Deserialize, Serialize};

use std::{
fmt::Display,
io::Write,
process::{Command, Stdio},
};

use serde::{Deserialize, Serialize};

use super::logging::Logger;
use crate::infrastructure::logging::Logger;

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub enum CoverRenderer {
Expand Down
27 changes: 0 additions & 27 deletions src/app/logging/log_on_error.rs

This file was deleted.

48 changes: 24 additions & 24 deletions src/app.rs → src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
pub mod config;
mod cover_renderer;
mod patch_renderer;
pub mod screens;

use ansi_to_tui::IntoText;
use color_eyre::eyre::bail;
use ratatui::text::Text;

use std::collections::{HashMap, HashSet};

use crate::{
infrastructure::{garbage_collector, logging::Logger},
log_on_error,
lore::{
lore_api_client::BlockingLoreAPIClient,
lore_session,
patch::{Author, Patch},
},
ui::popup::{info_popup::InfoPopUp, PopUp},
};
use ansi_to_tui::IntoText;
use color_eyre::eyre::bail;

use config::Config;
use cover_renderer::render_cover;
use logging::Logger;
use patch_hub::lore::{
lore_api_client::BlockingLoreAPIClient,
lore_session,
patch::{Author, Patch},
};
use patch_renderer::{render_patch_preview, PatchRenderer};
use ratatui::text::Text;
use screens::{
bookmarked::BookmarkedPatchsets,
details_actions::{DetailsActions, PatchsetAction},
Expand All @@ -22,15 +31,6 @@ use screens::{
mail_list::MailingListSelection,
CurrentScreen,
};
use std::collections::{HashMap, HashSet};

use crate::utils;

pub mod config;
pub mod cover_renderer;
pub mod logging;
pub mod patch_renderer;
pub mod screens;

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

Ok(App {
current_screen: CurrentScreen::MailingListSelection,
Expand Down Expand Up @@ -391,30 +391,30 @@ impl App {
pub fn check_external_deps(&self) -> bool {
let mut app_can_run = true;

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

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

match self.config.patch_renderer() {
PatchRenderer::Bat => {
if !utils::binary_exists("bat") {
if which::which("bat").is_err() {
Logger::warn("bat is not installed, patch rendering will fallback to default");
}
}
PatchRenderer::Delta => {
if !utils::binary_exists("delta") {
if which::which("delta").is_err() {
Logger::warn(
"delta is not installed, patch rendering will fallback to default",
);
}
}
PatchRenderer::DiffSoFancy => {
if !utils::binary_exists("diff-so-fancy") {
if which::which("diff-so-fancy").is_err() {
Logger::warn(
"diff-so-fancy is not installed, patch rendering will fallback to default",
);
Expand Down
8 changes: 4 additions & 4 deletions src/app/patch_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use color_eyre::eyre::eyre;
use serde::{Deserialize, Serialize};

use std::{
fmt::Display,
io::Write,
process::{Command, Stdio},
};

use color_eyre::eyre::eyre;
use serde::{Deserialize, Serialize};

use super::logging::Logger;
use crate::infrastructure::logging::Logger;

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub enum PatchRenderer {
Expand Down
2 changes: 1 addition & 1 deletion src/app/screens/bookmarked.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use patch_hub::lore::patch::Patch;
use crate::lore::patch::Patch;

pub struct BookmarkedPatchsets {
pub bookmarked_patchsets: Vec<Patch>,
Expand Down
17 changes: 12 additions & 5 deletions src/app/screens/details_actions.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use crate::app::config::{Config, KernelTree};

use super::CurrentScreen;
use ::patch_hub::lore::{lore_api_client::BlockingLoreAPIClient, lore_session, patch::Patch};
use color_eyre::eyre::{bail, eyre};
use patch_hub::lore::patch::Author;
use ratatui::text::Text;

use std::{
collections::{HashMap, HashSet},
path::Path,
process::Command,
};

use crate::{
app::config::{Config, KernelTree},
lore::{
lore_api_client::BlockingLoreAPIClient,
lore_session,
patch::{Author, Patch},
},
};

use super::CurrentScreen;

pub struct DetailsActions {
pub representative_patch: Patch,
/// Raw patches as plain text files
Expand Down
5 changes: 3 additions & 2 deletions src/app/screens/edit_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use color_eyre::eyre::bail;
use derive_getters::Getters;

use std::{collections::HashMap, fmt::Display, path::Path};

use crate::app::config::Config;
use color_eyre::eyre::bail;
use derive_getters::Getters;

#[derive(Debug, Getters)]
pub struct EditConfig {
Expand Down
3 changes: 2 additions & 1 deletion src/app/screens/latest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use color_eyre::eyre::bail;
use derive_getters::Getters;
use patch_hub::lore::{

use crate::lore::{
lore_api_client::{BlockingLoreAPIClient, ClientError},
lore_session::{LoreSession, LoreSessionError},
patch::Patch,
Expand Down
3 changes: 2 additions & 1 deletion src/app/screens/mail_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use color_eyre::eyre::bail;
use patch_hub::lore::{

use crate::lore::{
lore_api_client::BlockingLoreAPIClient, lore_session, mailing_list::MailingList,
};

Expand Down
8 changes: 4 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::ops::ControlFlow;

use clap::Parser;
use color_eyre::eyre::eyre;
use ratatui::{prelude::Backend, Terminal};

use crate::{app::config::Config, utils};
use std::ops::ControlFlow;

use crate::{app::config::Config, infrastructure::terminal::restore};

#[derive(Debug, Parser)]
#[command(version, about)]
Expand All @@ -25,7 +25,7 @@ impl Cli {
) -> ControlFlow<color_eyre::Result<()>, Terminal<B>> {
if self.show_configs {
drop(terminal);
if let Err(err) = utils::restore() {
if let Err(err) = restore() {
return ControlFlow::Break(Err(eyre!(err)));
}
match serde_json::to_string_pretty(&config) {
Expand Down
11 changes: 6 additions & 5 deletions src/handler/bookmarked.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
ui::popup::{help::HelpPopUpBuilder, PopUp},
};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

pub fn handle_bookmarked_patchsets<B>(
app: &mut App,
Expand Down
17 changes: 9 additions & 8 deletions src/handler/details_actions.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use ratatui::{
backend::Backend,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
Terminal,
};

use std::time::Duration;

use crate::{
app::{screens::CurrentScreen, App},
infrastructure::terminal::{setup_user_io, teardown_user_io},
ui::popup::{help::HelpPopUpBuilder, review_trailers::ReviewTrailersPopUp, PopUp},
utils,
};
use ratatui::{
backend::Backend,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
Terminal,
};

use super::wait_key_press;
Expand Down Expand Up @@ -107,7 +108,7 @@ pub fn handle_patchset_details<B: Backend>(
}
KeyCode::Enter => {
if patchset_details_and_actions.actions_require_user_io() {
utils::setup_user_io(terminal)?;
setup_user_io(terminal)?;
app.consolidate_patchset_actions()?;
println!("\nPress ENTER continue...");
loop {
Expand All @@ -117,7 +118,7 @@ pub fn handle_patchset_details<B: Backend>(
}
}
}
utils::teardown_user_io(terminal)?;
teardown_user_io(terminal)?;
} else {
app.consolidate_patchset_actions()?;
}
Expand Down
3 changes: 2 additions & 1 deletion src/handler/edit_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use ratatui::crossterm::event::{KeyCode, KeyEvent};

use crate::{
app::{screens::CurrentScreen, App},
ui::popup::{help::HelpPopUpBuilder, PopUp},
};
use ratatui::crossterm::event::{KeyCode, KeyEvent};

pub fn handle_edit_config(app: &mut App, key: KeyEvent) -> color_eyre::Result<()> {
if let Some(edit_config_state) = app.edit_config.as_mut() {
Expand Down
11 changes: 6 additions & 5 deletions src/handler/latest.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
ui::popup::{help::HelpPopUpBuilder, PopUp},
};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

pub fn handle_latest_patchsets<B>(
app: &mut App,
Expand Down
11 changes: 6 additions & 5 deletions src/handler/mail_list.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
ui::popup::{help::HelpPopUpBuilder, PopUp},
};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
prelude::Backend,
Terminal,
};

pub fn handle_mailing_list_selection<B>(
app: &mut App,
Expand Down
Loading