Skip to content
Open
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
471 changes: 336 additions & 135 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ regex = "1.11.1"
serde = { version = "1.0.219", features = ["derive"] }
serde-xml-rs = "0.8.1"
serde_json = "1.0.140"
tracing = "0.1"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = ["fmt", "std", "json"] }
thiserror = "2.0.12"
clap = { version = "4.5.40", features = ["derive"] }
chrono = "0.4.41"
Expand Down
5 changes: 2 additions & 3 deletions src/app/cover_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{
io::Write,
process::{Command, Stdio},
};

use crate::infrastructure::logging::Logger;
use tracing::{event, Level};

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub enum CoverRenderer {
Expand Down Expand Up @@ -68,7 +67,7 @@ fn bat_cover_renderer(patch: &str) -> color_eyre::Result<String> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| {
Logger::error(format!("Failed to spawn bat for cover preview: {e}"));
event!(Level::ERROR, "Failed to spawn bat for cover preview: {}", e);
e
})?;

Expand Down
38 changes: 24 additions & 14 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ pub mod screens;
use ansi_to_tui::IntoText;
use color_eyre::eyre::bail;
use ratatui::text::Text;
use tracing::{event, Level};

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

use crate::{
infrastructure::{garbage_collector, logging::Logger},
infrastructure::monitoring::logging::garbage_collector::collect_garbage,
log_on_error,
lore::{
lore_api_client::BlockingLoreAPIClient,
Expand Down Expand Up @@ -59,8 +60,7 @@ pub struct App {
impl App {
/// Creates a new instance of `App`. It dynamically loads configurations
/// based on precedence (see [crate::app::Config::build]), app data
/// (available mailing lists, bookmarked patchsets, reviewed patchsets), and
/// initializes the Logger (see [crate::app::logging::Logger])
/// (available mailing lists, bookmarked patchsets, reviewed patchsets)
///
/// # Returns
///
Expand All @@ -79,10 +79,8 @@ impl App {

let lore_api_client = BlockingLoreAPIClient::default();

// Initialize the logger before the app starts
Logger::init_log_file(&config)?;
Logger::info("patch-hub started");
garbage_collector::collect_garbage(&config);
event!(Level::INFO, "patch-hub started");
collect_garbage(&config);

Ok(App {
current_screen: CurrentScreen::MailingListSelection,
Expand Down Expand Up @@ -216,7 +214,10 @@ impl App {
{
Ok(render) => render,
Err(_) => {
Logger::error("Failed to render cover preview with external program");
event!(
Level::ERROR,
"Failed to render cover preview with external program"
);
raw_cover.to_string()
}
};
Expand All @@ -225,7 +226,8 @@ impl App {
match render_patch_preview(raw_patch, self.config.patch_renderer()) {
Ok(render) => render,
Err(_) => {
Logger::error(
event!(
Level::ERROR,
"Failed to render patch preview with external program",
);
raw_patch.to_string()
Expand Down Expand Up @@ -404,30 +406,38 @@ impl App {
let mut app_can_run = true;

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

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

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

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

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

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub enum PatchRenderer {
#[default]
Expand Down Expand Up @@ -100,7 +99,7 @@ fn bat_patch_renderer(patch: &str) -> color_eyre::Result<String> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| {
Logger::error(format!("Failed to spawn bat for patch preview: {e}"));
event!(Level::ERROR, "Failed to spawn bat for patch preview: {}", e);
e
})?;

Expand Down Expand Up @@ -136,7 +135,11 @@ fn delta_patch_renderer(patch: &str) -> color_eyre::Result<String> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| {
Logger::error(format!("Failed to spawn delta for patch preview: {e}"));
event!(
Level::ERROR,
"Failed to spawn delta for patch preview: {}",
e
);
e
})?;

Expand Down Expand Up @@ -166,9 +169,11 @@ fn diff_so_fancy_renderer(patch: &str) -> color_eyre::Result<String> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| {
Logger::error(format!(
"Failed to spawn diff-so-fancy for patch preview: {e}"
));
event!(
Level::ERROR,
"Failed to spawn diff-so-fancy for patch preview: {}",
e
);
e
})?;

Expand Down
8 changes: 4 additions & 4 deletions src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod latest;
mod mail_list;

use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind},
crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind},
prelude::Backend,
Terminal,
};
Expand Down Expand Up @@ -116,7 +116,7 @@ where
// need to refresh the UI independently of any event as doing so gravely
// hinders the performance to below acceptable.
// if event::poll(Duration::from_millis(16))? {
if let Event::Key(key) = event::read()? {
if let Event::Key(key) = ratatui::crossterm::event::read()? {
if key.kind == KeyEventKind::Release {
continue;
}
Expand All @@ -133,8 +133,8 @@ fn wait_key_press(ch: char, wait_time: Duration) -> color_eyre::Result<bool> {
let start = Instant::now();

while Instant::now() - start < wait_time {
if event::poll(Duration::from_millis(16))? {
if let Event::Key(key) = event::read()? {
if ratatui::crossterm::event::poll(Duration::from_millis(16))? {
if let Event::Key(key) = ratatui::crossterm::event::read()? {
if key.kind == KeyEventKind::Release {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/infrastructure/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::panic;

use super::{logging::Logger, terminal::restore};
use super::terminal::restore;

/// This replaces the standard color_eyre panic and error hooks with hooks that
/// restore the terminal before printing the panic or error.
Expand All @@ -11,7 +11,6 @@ pub fn install_hooks() -> color_eyre::Result<()> {
let panic_hook = panic_hook.into_panic_hook();
panic::set_hook(Box::new(move |panic_info| {
restore().unwrap();
Logger::flush();
panic_hook(panic_info);
}));

Expand Down
Loading
Loading