Skip to content
Draft
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
72 changes: 19 additions & 53 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
pub mod commands;
pub mod cover_renderer;
pub mod errors;
pub mod patch_renderer;
pub mod screens;
pub mod state;
pub mod view_model;

use ansi_to_tui::IntoText;
use color_eyre::eyre::{bail, eyre};
use ratatui::text::Text;
use tracing::{event, Level};

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

use crate::{
config::ConfigServiceApi,
infrastructure::{
env::EnvTrait,
file_system::FileSystemTrait,
monitoring::logging::garbage_collector::collect_garbage,
render::RenderServiceApi,
shell::{ShellCommand, ShellTrait},
},
lore::{
Expand All @@ -31,8 +23,9 @@ use crate::{
errors::LoreError,
handle::LoreApiHandle,
},
domain::patch::{Author, Patch},
domain::patch::Patch,
},
render::{handle::RenderHandle, RenderPatchsetRequest},
ui::popup::info_popup::InfoPopUp,
};
use screens::{
Expand All @@ -49,7 +42,7 @@ pub use view_model::AppViewModel;
/// Injected capabilities used by `App` orchestration (not screen state).
pub struct AppServices {
pub lore_api: LoreApiHandle,
pub render: Box<dyn RenderServiceApi>,
pub render: RenderHandle,
pub shell: Box<dyn ShellTrait>,
pub fs: Box<dyn FileSystemTrait>,
pub env: Box<dyn EnvTrait>,
Expand Down Expand Up @@ -82,7 +75,7 @@ impl App {
shell: Box<dyn ShellTrait>,
env: Box<dyn EnvTrait>,
lore_api: LoreApiHandle,
render: Box<dyn RenderServiceApi>,
render: RenderHandle,
) -> color_eyre::Result<Self> {
let config = config_service.snapshot();

Expand Down Expand Up @@ -219,52 +212,25 @@ impl App {
Err(e) => bail!("{e:#?}"),
};

let preview_lines = self
let render_request = RenderPatchsetRequest::new(
details.raw_patches.clone(),
*self.state.config.patch_renderer(),
*self.state.config.cover_renderer(),
);
let rendered_preview = self
.services
.render
.render_patchset_preview(
&details.raw_patches,
self.state.config.patch_renderer(),
self.state.config.cover_renderer(),
)
.render_patchset_preview(render_request)
.await
.map_err(|e| eyre!("{e}"))?;

let mut patches_preview: Vec<Text> = Vec::new();
let mut reviewed_by: Vec<HashSet<Author>> = Vec::new();
let mut tested_by: Vec<HashSet<Author>> = Vec::new();
let mut acked_by: Vec<HashSet<Author>> = Vec::new();

for (line, tag_summary) in preview_lines.iter().zip(details.tag_summary.iter()) {
reviewed_by.push(tag_summary.reviewed_by.clone());
tested_by.push(tag_summary.tested_by.clone());
acked_by.push(tag_summary.acked_by.clone());
patches_preview.push(line.as_str().into_text()?);
}

let has_cover_letter = representative_patch.number_in_series() == 0;
let patches_to_reply = vec![false; details.raw_patches.len()];

self.state.lore.details = Some(PatchsetDetailsState {
self.state.lore.details = Some(PatchsetDetailsState::from_rendered_preview(
representative_patch,
raw_patches: details.raw_patches,
patchset_path: details.patchset_path,
patches_preview,
patches_to_reply,
has_cover_letter,
preview_index: 0,
preview_scroll_offset: 0,
preview_pan: 0,
preview_fullscreen: false,
patchset_actions: HashMap::from([
(PatchsetAction::Bookmark, is_patchset_bookmarked),
(PatchsetAction::ReplyWithReviewedBy, false),
(PatchsetAction::Apply, false),
]),
reviewed_by,
tested_by,
acked_by,
last_screen: self.state.navigation.current_screen.clone(),
});
details,
rendered_preview,
is_patchset_bookmarked,
self.state.navigation.current_screen.clone(),
)?);

Ok(B4Result::PatchFound)
}
Expand Down
56 changes: 55 additions & 1 deletion src/app/screens/details_actions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ansi_to_tui::IntoText;
use ratatui::text::Text;

use std::collections::{HashMap, HashSet};
Expand All @@ -9,7 +10,11 @@ use crate::{
file_system::FileSystemTrait,
shell::{ShellCommand, ShellTrait},
},
lore::domain::patch::{Author, Patch},
lore::{
application::dto::PatchsetDetails,
domain::patch::{Author, Patch},
},
render::RenderedPatchsetPreview,
};

use super::CurrentScreen;
Expand Down Expand Up @@ -53,6 +58,55 @@ pub enum PatchsetAction {
}

impl PatchsetDetailsState {
pub fn from_rendered_preview(
representative_patch: Patch,
details: PatchsetDetails,
rendered_preview: RenderedPatchsetPreview,
is_patchset_bookmarked: bool,
last_screen: CurrentScreen,
) -> color_eyre::Result<Self> {
let mut patches_preview: Vec<Text> = Vec::new();
let mut reviewed_by: Vec<HashSet<Author>> = Vec::new();
let mut tested_by: Vec<HashSet<Author>> = Vec::new();
let mut acked_by: Vec<HashSet<Author>> = Vec::new();

for (entry, tag_summary) in rendered_preview
.entries
.iter()
.zip(details.tag_summary.iter())
{
reviewed_by.push(tag_summary.reviewed_by.clone());
tested_by.push(tag_summary.tested_by.clone());
acked_by.push(tag_summary.acked_by.clone());
patches_preview.push(entry.rendered_text.as_str().into_text()?);
}

let has_cover_letter = representative_patch.number_in_series() == 0;
let patches_to_reply = vec![false; details.raw_patches.len()];

Ok(Self {
representative_patch,
raw_patches: details.raw_patches,
patchset_path: details.patchset_path,
patches_preview,
patches_to_reply,
has_cover_letter,
preview_index: 0,
preview_scroll_offset: 0,
preview_pan: 0,
preview_fullscreen: false,
patchset_actions: HashMap::from([
(PatchsetAction::Bookmark, is_patchset_bookmarked),
(PatchsetAction::ReplyWithReviewedBy, false),
(PatchsetAction::Apply, false),
]),
reviewed_by,
tested_by,
acked_by,
last_screen,
})
}

pub fn preview_next_patch(&mut self) {
if (self.preview_index + 1) < self.patches_preview.len() {
self.preview_index += 1;
Expand Down
1 change: 0 additions & 1 deletion src/infrastructure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ pub mod errors;
pub mod file_system;
pub mod monitoring;
pub mod net;
pub mod render;
pub mod shell;
pub mod terminal;
69 changes: 0 additions & 69 deletions src/infrastructure/render/mod.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/infrastructure/render/tests.rs

This file was deleted.

8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ mod handler;
mod infrastructure;
mod lore;
mod macros;
mod render;
mod render_prefs;
mod ui;

use app::{patch_renderer::PatchRenderer, App};
use app::App;
use clap::Parser;
use cli::Cli;
use color_eyre::eyre::{bail, eyre};
Expand All @@ -19,7 +20,6 @@ use infrastructure::{
file_system::OsFileSystem,
monitoring::{init_monitoring, InitMonitoringProduct},
net::UreqNetClient,
render::{RenderServiceApi, ShellRenderService},
shell::OsShell,
terminal::{init, restore},
};
Expand All @@ -32,6 +32,8 @@ use lore::{
persistence::{FileLorePersistence, MailingListsCacheStore, UserLoreStateStore},
},
};
use render::{actor::RenderActor, ShellRenderService};
use render_prefs::PatchRenderer;
use std::{ops::ControlFlow, sync::Arc};
use tracing::{event, Level};

Expand Down Expand Up @@ -135,7 +137,7 @@ async fn main() -> color_eyre::Result<()> {
));
let parser = Arc::new(MboxPatchsetParser::new(fs_arc.clone()));

let render: Box<dyn RenderServiceApi> = Box::new(ShellRenderService::new(shell_arc.clone()));
let render = RenderActor::spawn(Box::new(ShellRenderService::new(shell_arc.clone())));

let lore_api = LoreApiActor::spawn(LoreService::new(
gateway.clone(),
Expand Down
Loading