diff --git a/src/app.rs b/src/app.rs index bb8d0333..c25f72bf 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,23 +2,23 @@ use crate::{ accessors, cmdbar::CommandBar, components::{ - command_pump, event_pump, AppOption, BlameFileComponent, - BranchListComponent, CommandInfo, CommitComponent, - CompareCommitsComponent, Component, ConfirmComponent, - CreateBranchComponent, DrawableComponent, - ExternalEditorComponent, FetchComponent, FileRevlogComponent, - FuzzyFindPopup, FuzzyFinderTarget, HelpComponent, - InspectCommitComponent, LogSearchPopupComponent, - MsgComponent, OptionsPopupComponent, PullComponent, - PushComponent, PushTagsComponent, RenameBranchComponent, - ResetPopupComponent, RevisionFilesPopup, StashMsgComponent, - SubmodulesListComponent, TagCommitComponent, - TagListComponent, + command_pump, event_pump, CommandInfo, Component, + DrawableComponent, FuzzyFinderTarget, }, input::{Input, InputEvent, InputState}, keys::{key_match, KeyConfig, SharedKeyConfig}, options::{Options, SharedOptions}, popup_stack::PopupStack, + popups::{ + AppOption, BlameFilePopup, BranchListPopup, CommitPopup, + CompareCommitsPopup, ConfirmPopup, CreateBranchPopup, + ExternalEditorPopup, FetchPopup, FileRevlogPopup, + FuzzyFindPopup, HelpPopup, InspectCommitPopup, + LogSearchPopupPopup, MsgPopup, OptionsPopup, PullPopup, + PushPopup, PushTagsPopup, RenameBranchPopup, ResetPopup, + RevisionFilesPopup, StashMsgPopup, SubmodulesListPopup, + TagCommitPopup, TagListPopup, + }, queue::{ Action, AppTabs, InternalEvent, NeedsUpdate, Queue, StackablePopupOpen, @@ -68,31 +68,31 @@ pub enum QuitState { pub struct App { repo: RepoPathRef, do_quit: QuitState, - help: HelpComponent, - msg: MsgComponent, - reset: ConfirmComponent, - commit: CommitComponent, - blame_file_popup: BlameFileComponent, - file_revlog_popup: FileRevlogComponent, - stashmsg_popup: StashMsgComponent, - inspect_commit_popup: InspectCommitComponent, - compare_commits_popup: CompareCommitsComponent, - external_editor_popup: ExternalEditorComponent, + help_popup: HelpPopup, + msg_popup: MsgPopup, + confirm_popup: ConfirmPopup, + commit_popup: CommitPopup, + blame_file_popup: BlameFilePopup, + file_revlog_popup: FileRevlogPopup, + stashmsg_popup: StashMsgPopup, + inspect_commit_popup: InspectCommitPopup, + compare_commits_popup: CompareCommitsPopup, + external_editor_popup: ExternalEditorPopup, revision_files_popup: RevisionFilesPopup, fuzzy_find_popup: FuzzyFindPopup, - log_search_popup: LogSearchPopupComponent, - push_popup: PushComponent, - push_tags_popup: PushTagsComponent, - pull_popup: PullComponent, - fetch_popup: FetchComponent, - tag_commit_popup: TagCommitComponent, - create_branch_popup: CreateBranchComponent, - rename_branch_popup: RenameBranchComponent, - select_branch_popup: BranchListComponent, - options_popup: OptionsPopupComponent, - submodule_popup: SubmodulesListComponent, - tags_popup: TagListComponent, - reset_popup: ResetPopupComponent, + log_search_popup: LogSearchPopupPopup, + push_popup: PushPopup, + push_tags_popup: PushTagsPopup, + pull_popup: PullPopup, + fetch_popup: FetchPopup, + tag_commit_popup: TagCommitPopup, + create_branch_popup: CreateBranchPopup, + rename_branch_popup: RenameBranchPopup, + select_branch_popup: BranchListPopup, + options_popup: OptionsPopup, + submodule_popup: SubmodulesListPopup, + tags_popup: TagListPopup, + reset_popup: ResetPopup, cmdbar: RefCell, tab: usize, revlog: Revlog, @@ -171,39 +171,39 @@ impl App { let mut app = Self { input, - reset: ConfirmComponent::new(&env), - commit: CommitComponent::new(&env), - blame_file_popup: BlameFileComponent::new( + confirm_popup: ConfirmPopup::new(&env), + commit_popup: CommitPopup::new(&env), + blame_file_popup: BlameFilePopup::new( &env, &strings::blame_title(&env.key_config), ), - file_revlog_popup: FileRevlogComponent::new(&env), + file_revlog_popup: FileRevlogPopup::new(&env), revision_files_popup: RevisionFilesPopup::new(&env), - stashmsg_popup: StashMsgComponent::new(&env), - inspect_commit_popup: InspectCommitComponent::new(&env), - compare_commits_popup: CompareCommitsComponent::new(&env), - external_editor_popup: ExternalEditorComponent::new(&env), - push_popup: PushComponent::new(&env), - push_tags_popup: PushTagsComponent::new(&env), - reset_popup: ResetPopupComponent::new(&env), - pull_popup: PullComponent::new(&env), - fetch_popup: FetchComponent::new(&env), - tag_commit_popup: TagCommitComponent::new(&env), - create_branch_popup: CreateBranchComponent::new(&env), - rename_branch_popup: RenameBranchComponent::new(&env), - select_branch_popup: BranchListComponent::new(&env), - tags_popup: TagListComponent::new(&env), - options_popup: OptionsPopupComponent::new(&env), - submodule_popup: SubmodulesListComponent::new(&env), - log_search_popup: LogSearchPopupComponent::new(&env), + stashmsg_popup: StashMsgPopup::new(&env), + inspect_commit_popup: InspectCommitPopup::new(&env), + compare_commits_popup: CompareCommitsPopup::new(&env), + external_editor_popup: ExternalEditorPopup::new(&env), + push_popup: PushPopup::new(&env), + push_tags_popup: PushTagsPopup::new(&env), + reset_popup: ResetPopup::new(&env), + pull_popup: PullPopup::new(&env), + fetch_popup: FetchPopup::new(&env), + tag_commit_popup: TagCommitPopup::new(&env), + create_branch_popup: CreateBranchPopup::new(&env), + rename_branch_popup: RenameBranchPopup::new(&env), + select_branch_popup: BranchListPopup::new(&env), + tags_popup: TagListPopup::new(&env), + options_popup: OptionsPopup::new(&env), + submodule_popup: SubmodulesListPopup::new(&env), + log_search_popup: LogSearchPopupPopup::new(&env), fuzzy_find_popup: FuzzyFindPopup::new(&env), do_quit: QuitState::None, cmdbar: RefCell::new(CommandBar::new( env.theme.clone(), env.key_config.clone(), )), - help: HelpComponent::new(&env), - msg: MsgComponent::new(&env), + help_popup: HelpPopup::new(&env), + msg_popup: MsgPopup::new(&env), revlog: Revlog::new(&env), status_tab: Status::new(&env), stashing_tab: Stashing::new(&env), @@ -345,21 +345,21 @@ impl App { if matches!(polling_state, InputState::Paused) { let result = if let Some(path) = self.file_to_open.take() { - ExternalEditorComponent::open_file_in_editor( + ExternalEditorPopup::open_file_in_editor( &self.repo.borrow(), Path::new(&path), ) } else { let changes = self.status_tab.get_files_changes()?; - self.commit.show_editor(changes) + self.commit_popup.show_editor(changes) }; if let Err(e) = result { let msg = format!("failed to launch editor:\n{e}"); log::error!("{}", msg.as_str()); - self.msg.show_error(msg.as_str())?; + self.msg_popup.show_error(msg.as_str())?; } self.requires_redraw.set(true); @@ -375,7 +375,7 @@ impl App { pub fn update(&mut self) -> Result<()> { log::trace!("update"); - self.commit.update(); + self.commit_popup.update(); self.status_tab.update()?; self.revlog.update()?; self.files_tab.update()?; @@ -469,9 +469,9 @@ impl App { [ log_search_popup, fuzzy_find_popup, - msg, - reset, - commit, + msg_popup, + confirm_popup, + commit_popup, blame_file_popup, file_revlog_popup, stashmsg_popup, @@ -491,7 +491,7 @@ impl App { tags_popup, reset_popup, options_popup, - help, + help_popup, revlog, status_tab, files_tab, @@ -503,9 +503,9 @@ impl App { setup_popups!( self, [ - commit, + commit_popup, stashmsg_popup, - help, + help_popup, inspect_commit_popup, compare_commits_popup, blame_file_popup, @@ -526,8 +526,8 @@ impl App { pull_popup, fetch_popup, options_popup, - reset, - msg + confirm_popup, + msg_popup ] ); @@ -619,8 +619,8 @@ impl App { } fn update_commands(&mut self) { - if self.help.is_visible() { - self.help.set_cmds(self.commands(true)); + if self.help_popup.is_visible() { + self.help_popup.set_cmds(self.commands(true)); } self.cmdbar.borrow_mut().set_cmds(self.commands(false)); } @@ -703,23 +703,23 @@ impl App { self.process_confirmed_action(action, &mut flags)?; } InternalEvent::ConfirmAction(action) => { - self.reset.open(action)?; + self.confirm_popup.open(action)?; flags.insert(NeedsUpdate::COMMANDS); } InternalEvent::ShowErrorMsg(msg) => { - self.msg.show_error(msg.as_str())?; + self.msg_popup.show_error(msg.as_str())?; flags .insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS); } InternalEvent::ShowInfoMsg(msg) => { - self.msg.show_info(msg.as_str())?; + self.msg_popup.show_info(msg.as_str())?; flags .insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS); } InternalEvent::Update(u) => flags.insert(u), - InternalEvent::OpenCommit => self.commit.show()?, + InternalEvent::OpenCommit => self.commit_popup.show()?, InternalEvent::RewordCommit(id) => { - self.commit.open(Some(id))?; + self.commit_popup.open(Some(id))?; } InternalEvent::PopupStashing(opts) => { self.stashmsg_popup.options(opts); diff --git a/src/components/mod.rs b/src/components/mod.rs index ae29777a..7b2b5a7e 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,75 +1,30 @@ -mod blame_file; -mod branchlist; mod changes; mod command; -mod commit; mod commit_details; mod commitlist; -mod compare_commits; -mod create_branch; mod cred; mod diff; -mod externaleditor; -mod fetch; -mod file_revlog; -mod fuzzy_find_popup; -mod help; -mod inspect_commit; -mod log_search_popup; -mod msg; -mod options_popup; -mod pull; -mod push; -mod push_tags; -mod rename_branch; -mod reset; -mod reset_popup; mod revision_files; -mod revision_files_popup; -mod stashmsg; mod status_tree; -mod submodules; mod syntax_text; -mod tag_commit; -mod taglist; mod textinput; mod utils; pub use self::status_tree::StatusTreeComponent; -pub use blame_file::{BlameFileComponent, BlameFileOpen}; -pub use branchlist::BranchListComponent; pub use changes::ChangesComponent; pub use command::{CommandInfo, CommandText}; -pub use commit::CommitComponent; pub use commit_details::CommitDetailsComponent; pub use commitlist::CommitList; -pub use compare_commits::CompareCommitsComponent; -pub use create_branch::CreateBranchComponent; +pub use cred::CredComponent; pub use diff::DiffComponent; -pub use externaleditor::ExternalEditorComponent; -pub use fetch::FetchComponent; -pub use file_revlog::{FileRevOpen, FileRevlogComponent}; -pub use fuzzy_find_popup::FuzzyFindPopup; -pub use help::HelpComponent; -pub use inspect_commit::{InspectCommitComponent, InspectCommitOpen}; -pub use log_search_popup::LogSearchPopupComponent; -pub use msg::MsgComponent; -pub use options_popup::{AppOption, OptionsPopupComponent}; -pub use pull::PullComponent; -pub use push::PushComponent; -pub use push_tags::PushTagsComponent; -pub use rename_branch::RenameBranchComponent; -pub use reset::ConfirmComponent; -pub use reset_popup::ResetPopupComponent; pub use revision_files::RevisionFilesComponent; -pub use revision_files_popup::{FileTreeOpen, RevisionFilesPopup}; -pub use stashmsg::StashMsgComponent; -pub use submodules::SubmodulesListComponent; pub use syntax_text::SyntaxTextComponent; -pub use tag_commit::TagCommitComponent; -pub use taglist::TagListComponent; pub use textinput::{InputType, TextInputComponent}; -pub use utils::filetree::FileTreeItemKind; +pub use utils::{ + filetree::FileTreeItemKind, logitems::ItemBatch, + scroll_vertical::VerticalScroll, string_width_align, + time_to_string, +}; use crate::ui::style::Theme; use anyhow::Result; @@ -78,7 +33,7 @@ use ratatui::{ backend::Backend, layout::{Alignment, Rect}, text::{Span, Text}, - widgets::{Block, BorderType, Borders, Paragraph, Wrap}, + widgets::{Block, Borders, Paragraph}, Frame, }; @@ -312,30 +267,3 @@ fn dialog_paragraph<'a>( ) .alignment(Alignment::Left) } - -fn popup_paragraph<'a, T>( - title: &'a str, - content: T, - theme: &Theme, - focused: bool, - block: bool, -) -> Paragraph<'a> -where - T: Into>, -{ - let paragraph = Paragraph::new(content.into()) - .alignment(Alignment::Left) - .wrap(Wrap { trim: true }); - - if block { - paragraph.block( - Block::default() - .title(Span::styled(title, theme.title(focused))) - .borders(Borders::ALL) - .border_type(BorderType::Thick) - .border_style(theme.block(focused)), - ) - } else { - paragraph - } -} diff --git a/src/components/revision_files.rs b/src/components/revision_files.rs index 62c3f685..d8725619 100644 --- a/src/components/revision_files.rs +++ b/src/components/revision_files.rs @@ -1,11 +1,12 @@ use super::{ - utils::scroll_vertical::VerticalScroll, BlameFileOpen, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, FileRevOpen, FuzzyFinderTarget, SyntaxTextComponent, + utils::scroll_vertical::VerticalScroll, CommandBlocking, + CommandInfo, Component, DrawableComponent, EventState, + FuzzyFinderTarget, SyntaxTextComponent, }; use crate::{ app::Environment, keys::{key_match, SharedKeyConfig}, + popups::{BlameFileOpen, FileRevOpen}, queue::{InternalEvent, Queue, StackablePopupOpen}, strings::{self, order, symbol}, try_or_popup, diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index 5c8c3692..a3087de3 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -3,16 +3,16 @@ use super::{ filetree::{FileTreeItem, FileTreeItemKind}, statustree::{MoveSelection, StatusTree}, }, - BlameFileOpen, CommandBlocking, DrawableComponent, FileRevOpen, + CommandBlocking, DrawableComponent, }; use crate::{ app::Environment, components::{CommandInfo, Component, EventState}, keys::{key_match, SharedKeyConfig}, + popups::{BlameFileOpen, FileRevOpen}, queue::{InternalEvent, NeedsUpdate, Queue, StackablePopupOpen}, strings::{self, order}, - ui, - ui::style::SharedTheme, + ui::{self, style::SharedTheme}, }; use anyhow::Result; use asyncgit::{hash, sync::CommitId, StatusItem, StatusItemType}; diff --git a/src/main.rs b/src/main.rs index 6c5f2352..96c806d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ mod keys; mod notify_mutex; mod options; mod popup_stack; +mod popups; mod queue; mod spinner; mod string_utils; diff --git a/src/components/blame_file.rs b/src/popups/blame_file.rs similarity index 97% rename from src/components/blame_file.rs rename to src/popups/blame_file.rs index 435284d4..93773ef5 100644 --- a/src/components/blame_file.rs +++ b/src/popups/blame_file.rs @@ -1,12 +1,12 @@ -use super::{ - utils, visibility_blocking, CommandBlocking, CommandInfo, - Component, DrawableComponent, EventState, FileRevOpen, - InspectCommitOpen, -}; use crate::{ app::Environment, - components::{utils::string_width_align, ScrollType}, + components::{ + string_width_align, time_to_string, visibility_blocking, + CommandBlocking, CommandInfo, Component, DrawableComponent, + EventState, ScrollType, + }, keys::{key_match, SharedKeyConfig}, + popups::{FileRevOpen, InspectCommitOpen}, queue::{InternalEvent, Queue, StackablePopupOpen}, string_utils::tabs_to_spaces, strings, @@ -84,7 +84,7 @@ pub struct BlameFileOpen { pub selection: Option, } -pub struct BlameFileComponent { +pub struct BlameFilePopup { title: String, theme: SharedTheme, queue: Queue, @@ -99,7 +99,7 @@ pub struct BlameFileComponent { git_sender: Sender, repo: RepoPathRef, } -impl DrawableComponent for BlameFileComponent { +impl DrawableComponent for BlameFilePopup { fn draw( &self, f: &mut Frame, @@ -192,7 +192,7 @@ impl DrawableComponent for BlameFileComponent { } } -impl Component for BlameFileComponent { +impl Component for BlameFilePopup { fn commands( &self, out: &mut Vec, @@ -329,7 +329,7 @@ impl Component for BlameFileComponent { } } -impl BlameFileComponent { +impl BlameFilePopup { /// pub fn new(env: &Environment, title: &str) -> Self { Self { @@ -648,7 +648,7 @@ impl BlameFileComponent { ); let author = format!("{truncated_author:MAX_AUTHOR_WIDTH$}"); let time = blame_hunk.map_or_else(String::new, |hunk| { - utils::time_to_string(hunk.time, true) + time_to_string(hunk.time, true) }); let file_blame = self.blame.result(); diff --git a/src/components/branchlist.rs b/src/popups/branchlist.rs similarity index 98% rename from src/components/branchlist.rs rename to src/popups/branchlist.rs index 81ad9b98..0b2299d8 100644 --- a/src/components/branchlist.rs +++ b/src/popups/branchlist.rs @@ -1,7 +1,6 @@ -use super::{ - utils::scroll_vertical::VerticalScroll, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, FuzzyFinderTarget, InspectCommitOpen, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, FuzzyFinderTarget, VerticalScroll, }; use crate::{ app::Environment, @@ -40,8 +39,10 @@ use std::cell::Cell; use ui::style::SharedTheme; use unicode_truncate::UnicodeTruncateStr; +use super::InspectCommitOpen; + /// -pub struct BranchListComponent { +pub struct BranchListPopup { repo: RepoPathRef, branches: Vec, local: bool, @@ -55,7 +56,7 @@ pub struct BranchListComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for BranchListComponent { +impl DrawableComponent for BranchListPopup { fn draw( &self, f: &mut Frame, @@ -105,7 +106,7 @@ impl DrawableComponent for BranchListComponent { } } -impl Component for BranchListComponent { +impl Component for BranchListPopup { fn commands( &self, out: &mut Vec, @@ -329,7 +330,7 @@ impl Component for BranchListComponent { } } -impl BranchListComponent { +impl BranchListPopup { pub fn new(env: &Environment) -> Self { Self { branches: Vec::new(), diff --git a/src/components/commit.rs b/src/popups/commit.rs similarity index 97% rename from src/components/commit.rs rename to src/popups/commit.rs index b2824956..4bf4a07b 100644 --- a/src/components/commit.rs +++ b/src/popups/commit.rs @@ -1,7 +1,6 @@ -use super::{ - textinput::TextInputComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, ExternalEditorComponent, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, TextInputComponent, }; use crate::{ app::Environment, @@ -35,6 +34,8 @@ use std::{ str::FromStr, }; +use super::ExternalEditorPopup; + enum CommitResult { ComitDone, Aborted, @@ -48,7 +49,7 @@ enum Mode { Reword(CommitId), } -pub struct CommitComponent { +pub struct CommitPopup { repo: RepoPathRef, input: TextInputComponent, mode: Mode, @@ -64,7 +65,7 @@ pub struct CommitComponent { const FIRST_LINE_LIMIT: usize = 50; -impl CommitComponent { +impl CommitPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -183,7 +184,7 @@ impl CommitComponent { } } - ExternalEditorComponent::open_file_in_editor( + ExternalEditorPopup::open_file_in_editor( &self.repo.borrow(), &file_path, )?; @@ -486,7 +487,7 @@ impl CommitComponent { } } -impl DrawableComponent for CommitComponent { +impl DrawableComponent for CommitPopup { fn draw( &self, f: &mut Frame, @@ -502,7 +503,7 @@ impl DrawableComponent for CommitComponent { } } -impl Component for CommitComponent { +impl Component for CommitPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/compare_commits.rs b/src/popups/compare_commits.rs similarity index 96% rename from src/components/compare_commits.rs rename to src/popups/compare_commits.rs index 19de2539..31a164cb 100644 --- a/src/components/compare_commits.rs +++ b/src/popups/compare_commits.rs @@ -1,13 +1,14 @@ -use super::{ +use crate::components::{ command_pump, event_pump, visibility_blocking, CommandBlocking, CommandInfo, CommitDetailsComponent, Component, DiffComponent, - DrawableComponent, EventState, InspectCommitOpen, + DrawableComponent, EventState, }; use crate::{ accessors, app::Environment, keys::{key_match, SharedKeyConfig}, options::SharedOptions, + popups::InspectCommitOpen, queue::{InternalEvent, Queue, StackablePopupOpen}, strings, }; @@ -25,7 +26,7 @@ use ratatui::{ Frame, }; -pub struct CompareCommitsComponent { +pub struct CompareCommitsPopup { repo: RepoPathRef, open_request: Option, diff: DiffComponent, @@ -37,7 +38,7 @@ pub struct CompareCommitsComponent { options: SharedOptions, } -impl DrawableComponent for CompareCommitsComponent { +impl DrawableComponent for CompareCommitsPopup { fn draw( &self, f: &mut Frame, @@ -71,7 +72,7 @@ impl DrawableComponent for CompareCommitsComponent { } } -impl Component for CompareCommitsComponent { +impl Component for CompareCommitsPopup { fn commands( &self, out: &mut Vec, @@ -163,7 +164,7 @@ impl Component for CompareCommitsComponent { } } -impl CompareCommitsComponent { +impl CompareCommitsPopup { accessors!(self, [diff, details]); /// diff --git a/src/components/reset.rs b/src/popups/confirm.rs similarity index 95% rename from src/components/reset.rs rename to src/popups/confirm.rs index 51d4781a..acdd9021 100644 --- a/src/components/reset.rs +++ b/src/popups/confirm.rs @@ -1,8 +1,8 @@ use crate::{ app::Environment, components::{ - popup_paragraph, visibility_blocking, CommandBlocking, - CommandInfo, Component, DrawableComponent, EventState, + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, }, keys::{key_match, SharedKeyConfig}, queue::{Action, InternalEvent, Queue}, @@ -16,8 +16,10 @@ use ratatui::{ use std::borrow::Cow; use ui::style::SharedTheme; +use super::popup_paragraph; + /// -pub struct ConfirmComponent { +pub struct ConfirmPopup { target: Option, visible: bool, queue: Queue, @@ -25,7 +27,7 @@ pub struct ConfirmComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for ConfirmComponent { +impl DrawableComponent for ConfirmPopup { fn draw( &self, f: &mut Frame, @@ -51,7 +53,7 @@ impl DrawableComponent for ConfirmComponent { } } -impl Component for ConfirmComponent { +impl Component for ConfirmPopup { fn commands( &self, out: &mut Vec, @@ -102,7 +104,7 @@ impl Component for ConfirmComponent { } } -impl ConfirmComponent { +impl ConfirmPopup { /// pub fn new(env: &Environment) -> Self { Self { diff --git a/src/components/create_branch.rs b/src/popups/create_branch.rs similarity index 90% rename from src/components/create_branch.rs rename to src/popups/create_branch.rs index 18e7f6a4..7dacd0fb 100644 --- a/src/components/create_branch.rs +++ b/src/popups/create_branch.rs @@ -1,7 +1,6 @@ -use super::{ - textinput::TextInputComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, InputType, TextInputComponent, }; use crate::{ app::Environment, @@ -18,7 +17,7 @@ use ratatui::{ backend::Backend, layout::Rect, widgets::Paragraph, Frame, }; -pub struct CreateBranchComponent { +pub struct CreateBranchPopup { repo: RepoPathRef, input: TextInputComponent, queue: Queue, @@ -26,7 +25,7 @@ pub struct CreateBranchComponent { theme: SharedTheme, } -impl DrawableComponent for CreateBranchComponent { +impl DrawableComponent for CreateBranchPopup { fn draw( &self, f: &mut Frame, @@ -41,7 +40,7 @@ impl DrawableComponent for CreateBranchComponent { } } -impl Component for CreateBranchComponent { +impl Component for CreateBranchPopup { fn commands( &self, out: &mut Vec, @@ -94,7 +93,7 @@ impl Component for CreateBranchComponent { } } -impl CreateBranchComponent { +impl CreateBranchPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -105,7 +104,7 @@ impl CreateBranchComponent { &strings::create_branch_popup_msg(&env.key_config), true, ) - .with_input_type(super::InputType::Singleline), + .with_input_type(InputType::Singleline), theme: env.theme.clone(), key_config: env.key_config.clone(), repo: env.repo.clone(), diff --git a/src/components/externaleditor.rs b/src/popups/externaleditor.rs similarity index 95% rename from src/components/externaleditor.rs rename to src/popups/externaleditor.rs index b343a9b7..e13ae3fd 100644 --- a/src/components/externaleditor.rs +++ b/src/popups/externaleditor.rs @@ -29,13 +29,13 @@ use std::ffi::OsStr; use std::{env, io, path::Path, process::Command}; /// -pub struct ExternalEditorComponent { +pub struct ExternalEditorPopup { visible: bool, theme: SharedTheme, key_config: SharedKeyConfig, } -impl ExternalEditorComponent { +impl ExternalEditorPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -120,7 +120,7 @@ impl ExternalEditorComponent { } } -impl DrawableComponent for ExternalEditorComponent { +impl DrawableComponent for ExternalEditorPopup { fn draw( &self, f: &mut Frame, @@ -155,7 +155,7 @@ impl DrawableComponent for ExternalEditorComponent { } } -impl Component for ExternalEditorComponent { +impl Component for ExternalEditorPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/fetch.rs b/src/popups/fetch.rs similarity index 94% rename from src/components/fetch.rs rename to src/popups/fetch.rs index d8a154ab..9c03f61c 100644 --- a/src/components/fetch.rs +++ b/src/popups/fetch.rs @@ -1,8 +1,8 @@ use crate::{ app::Environment, components::{ - cred::CredComponent, visibility_blocking, CommandBlocking, - CommandInfo, Component, DrawableComponent, EventState, + visibility_blocking, CommandBlocking, CommandInfo, Component, + CredComponent, DrawableComponent, EventState, }, keys::SharedKeyConfig, queue::{InternalEvent, NeedsUpdate, Queue}, @@ -32,7 +32,7 @@ use ratatui::{ }; /// -pub struct FetchComponent { +pub struct FetchPopup { repo: RepoPathRef, visible: bool, async_fetch: AsyncSingleJob, @@ -44,7 +44,7 @@ pub struct FetchComponent { input_cred: CredComponent, } -impl FetchComponent { +impl FetchPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -116,7 +116,7 @@ impl FetchComponent { } } -impl DrawableComponent for FetchComponent { +impl DrawableComponent for FetchPopup { fn draw( &self, f: &mut Frame, @@ -151,7 +151,7 @@ impl DrawableComponent for FetchComponent { } } -impl Component for FetchComponent { +impl Component for FetchPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/file_revlog.rs b/src/popups/file_revlog.rs similarity index 96% rename from src/components/file_revlog.rs rename to src/popups/file_revlog.rs index 2366ebda..8fb8349f 100644 --- a/src/components/file_revlog.rs +++ b/src/popups/file_revlog.rs @@ -1,16 +1,13 @@ -use super::utils::logitems::ItemBatch; -use super::{visibility_blocking, BlameFileOpen, InspectCommitOpen}; -use crate::app::Environment; -use crate::keys::key_match; -use crate::options::SharedOptions; -use crate::queue::StackablePopupOpen; use crate::{ + app::Environment, components::{ - event_pump, CommandBlocking, CommandInfo, Component, - DiffComponent, DrawableComponent, EventState, ScrollType, + event_pump, visibility_blocking, CommandBlocking, + CommandInfo, Component, DiffComponent, DrawableComponent, + EventState, ItemBatch, ScrollType, }, - keys::SharedKeyConfig, - queue::{InternalEvent, NeedsUpdate, Queue}, + keys::{key_match, SharedKeyConfig}, + options::SharedOptions, + queue::{InternalEvent, NeedsUpdate, Queue, StackablePopupOpen}, strings, ui::{draw_scrollbar, style::SharedTheme, Orientation}, }; @@ -32,6 +29,8 @@ use ratatui::{ Frame, }; +use super::{BlameFileOpen, InspectCommitOpen}; + const SLICE_SIZE: usize = 1200; #[derive(Clone, Debug)] @@ -50,7 +49,7 @@ impl FileRevOpen { } /// -pub struct FileRevlogComponent { +pub struct FileRevlogPopup { git_log: Option, git_diff: AsyncDiff, theme: SharedTheme, @@ -69,7 +68,7 @@ pub struct FileRevlogComponent { current_height: std::cell::Cell, } -impl FileRevlogComponent { +impl FileRevlogPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -464,7 +463,7 @@ impl FileRevlogComponent { } } -impl DrawableComponent for FileRevlogComponent { +impl DrawableComponent for FileRevlogPopup { fn draw( &self, f: &mut Frame, @@ -498,7 +497,7 @@ impl DrawableComponent for FileRevlogComponent { } } -impl Component for FileRevlogComponent { +impl Component for FileRevlogPopup { fn event(&mut self, event: &Event) -> Result { if self.is_visible() { if event_pump( diff --git a/src/components/fuzzy_find_popup.rs b/src/popups/fuzzy_find.rs similarity index 97% rename from src/components/fuzzy_find_popup.rs rename to src/popups/fuzzy_find.rs index ea92dfda..07dc1383 100644 --- a/src/components/fuzzy_find_popup.rs +++ b/src/popups/fuzzy_find.rs @@ -1,7 +1,7 @@ -use super::{ +use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, - DrawableComponent, EventState, FuzzyFinderTarget, ScrollType, - TextInputComponent, + DrawableComponent, EventState, FuzzyFinderTarget, InputType, + ScrollType, TextInputComponent, }; use crate::{ app::Environment, @@ -43,7 +43,7 @@ impl FuzzyFindPopup { pub fn new(env: &Environment) -> Self { let mut find_text = TextInputComponent::new(env, "", "start typing..", false) - .with_input_type(super::InputType::Singleline); + .with_input_type(InputType::Singleline); find_text.embed(); Self { diff --git a/src/components/help.rs b/src/popups/help.rs similarity index 97% rename from src/components/help.rs rename to src/popups/help.rs index 451ce7d3..716216f0 100644 --- a/src/components/help.rs +++ b/src/popups/help.rs @@ -1,4 +1,4 @@ -use super::{ +use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, DrawableComponent, EventState, }; @@ -24,7 +24,7 @@ use std::{borrow::Cow, cmp}; use ui::style::SharedTheme; /// -pub struct HelpComponent { +pub struct HelpPopup { cmds: Vec, visible: bool, selection: u16, @@ -32,7 +32,7 @@ pub struct HelpComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for HelpComponent { +impl DrawableComponent for HelpPopup { fn draw( &self, f: &mut Frame, @@ -87,7 +87,7 @@ impl DrawableComponent for HelpComponent { } } -impl Component for HelpComponent { +impl Component for HelpPopup { fn commands( &self, out: &mut Vec, @@ -167,7 +167,7 @@ impl Component for HelpComponent { } } -impl HelpComponent { +impl HelpPopup { pub fn new(env: &Environment) -> Self { Self { cmds: vec![], diff --git a/src/components/inspect_commit.rs b/src/popups/inspect_commit.rs similarity index 97% rename from src/components/inspect_commit.rs rename to src/popups/inspect_commit.rs index 1d737e69..96eba3fc 100644 --- a/src/components/inspect_commit.rs +++ b/src/popups/inspect_commit.rs @@ -1,4 +1,4 @@ -use super::{ +use crate::components::{ command_pump, event_pump, visibility_blocking, CommandBlocking, CommandInfo, CommitDetailsComponent, Component, DiffComponent, DrawableComponent, EventState, @@ -53,7 +53,7 @@ impl InspectCommitOpen { } } -pub struct InspectCommitComponent { +pub struct InspectCommitPopup { queue: Queue, open_request: Option, diff: DiffComponent, @@ -64,7 +64,7 @@ pub struct InspectCommitComponent { options: SharedOptions, } -impl DrawableComponent for InspectCommitComponent { +impl DrawableComponent for InspectCommitPopup { fn draw( &self, f: &mut Frame, @@ -98,7 +98,7 @@ impl DrawableComponent for InspectCommitComponent { } } -impl Component for InspectCommitComponent { +impl Component for InspectCommitPopup { fn commands( &self, out: &mut Vec, @@ -199,7 +199,7 @@ impl Component for InspectCommitComponent { } } -impl InspectCommitComponent { +impl InspectCommitPopup { accessors!(self, [diff, details]); /// diff --git a/src/components/log_search_popup.rs b/src/popups/log_search.rs similarity index 97% rename from src/components/log_search_popup.rs rename to src/popups/log_search.rs index b4279ac4..7179a348 100644 --- a/src/components/log_search_popup.rs +++ b/src/popups/log_search.rs @@ -1,6 +1,6 @@ -use super::{ +use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, - DrawableComponent, EventState, TextInputComponent, + DrawableComponent, EventState, InputType, TextInputComponent, }; use crate::{ app::Environment, @@ -41,7 +41,7 @@ enum PopupMode { JumpCommitSha, } -pub struct LogSearchPopupComponent { +pub struct LogSearchPopupPopup { repo: RepoPathRef, queue: Queue, visible: bool, @@ -54,12 +54,12 @@ pub struct LogSearchPopupComponent { jump_commit_id: Option, } -impl LogSearchPopupComponent { +impl LogSearchPopupPopup { /// pub fn new(env: &Environment) -> Self { let mut find_text = TextInputComponent::new(env, "", "search text", false) - .with_input_type(super::InputType::Singleline); + .with_input_type(InputType::Singleline); find_text.embed(); find_text.enabled(true); @@ -524,7 +524,7 @@ impl LogSearchPopupComponent { } } -impl DrawableComponent for LogSearchPopupComponent { +impl DrawableComponent for LogSearchPopupPopup { fn draw( &self, f: &mut Frame, @@ -545,7 +545,7 @@ impl DrawableComponent for LogSearchPopupComponent { } } -impl Component for LogSearchPopupComponent { +impl Component for LogSearchPopupPopup { fn commands( &self, out: &mut Vec, diff --git a/src/popups/mod.rs b/src/popups/mod.rs new file mode 100644 index 00000000..2216461a --- /dev/null +++ b/src/popups/mod.rs @@ -0,0 +1,85 @@ +mod blame_file; +mod branchlist; +mod commit; +mod compare_commits; +mod confirm; +mod create_branch; +mod externaleditor; +mod fetch; +mod file_revlog; +mod fuzzy_find; +mod help; +mod inspect_commit; +mod log_search; +mod msg; +mod options; +mod pull; +mod push; +mod push_tags; +mod rename_branch; +mod reset; +mod revision_files; +mod stashmsg; +mod submodules; +mod tag_commit; +mod taglist; + +pub use blame_file::{BlameFileOpen, BlameFilePopup}; +pub use branchlist::BranchListPopup; +pub use commit::CommitPopup; +pub use compare_commits::CompareCommitsPopup; +pub use confirm::ConfirmPopup; +pub use create_branch::CreateBranchPopup; +pub use externaleditor::ExternalEditorPopup; +pub use fetch::FetchPopup; +pub use file_revlog::{FileRevOpen, FileRevlogPopup}; +pub use fuzzy_find::FuzzyFindPopup; +pub use help::HelpPopup; +pub use inspect_commit::{InspectCommitOpen, InspectCommitPopup}; +pub use log_search::LogSearchPopupPopup; +pub use msg::MsgPopup; +pub use options::{AppOption, OptionsPopup}; +pub use pull::PullPopup; +pub use push::PushPopup; +pub use push_tags::PushTagsPopup; +pub use rename_branch::RenameBranchPopup; +pub use reset::ResetPopup; +pub use revision_files::{FileTreeOpen, RevisionFilesPopup}; +pub use stashmsg::StashMsgPopup; +pub use submodules::SubmodulesListPopup; +pub use tag_commit::TagCommitPopup; +pub use taglist::TagListPopup; + +use crate::ui::style::Theme; +use ratatui::{ + layout::Alignment, + text::{Span, Text}, + widgets::{Block, BorderType, Borders, Paragraph, Wrap}, +}; + +fn popup_paragraph<'a, T>( + title: &'a str, + content: T, + theme: &Theme, + focused: bool, + block: bool, +) -> Paragraph<'a> +where + T: Into>, +{ + let paragraph = Paragraph::new(content.into()) + .alignment(Alignment::Left) + .wrap(Wrap { trim: true }); + + if block { + paragraph.block( + Block::default() + .title(Span::styled(title, theme.title(focused))) + .borders(Borders::ALL) + .border_type(BorderType::Thick) + .border_style(theme.block(focused)), + ) + } else { + paragraph + } +} diff --git a/src/components/msg.rs b/src/popups/msg.rs similarity index 95% rename from src/components/msg.rs rename to src/popups/msg.rs index 7e461876..eb6d7611 100644 --- a/src/components/msg.rs +++ b/src/popups/msg.rs @@ -1,4 +1,4 @@ -use super::{ +use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, DrawableComponent, EventState, }; @@ -17,7 +17,7 @@ use ratatui::{ }; use ui::style::SharedTheme; -pub struct MsgComponent { +pub struct MsgPopup { title: String, msg: String, visible: bool, @@ -27,7 +27,7 @@ pub struct MsgComponent { use anyhow::Result; -impl DrawableComponent for MsgComponent { +impl DrawableComponent for MsgPopup { fn draw( &self, f: &mut Frame, @@ -78,7 +78,7 @@ impl DrawableComponent for MsgComponent { } } -impl Component for MsgComponent { +impl Component for MsgPopup { fn commands( &self, out: &mut Vec, @@ -121,7 +121,7 @@ impl Component for MsgComponent { } } -impl MsgComponent { +impl MsgPopup { pub fn new(env: &Environment) -> Self { Self { title: String::new(), diff --git a/src/components/options_popup.rs b/src/popups/options.rs similarity index 95% rename from src/components/options_popup.rs rename to src/popups/options.rs index c654ad1a..5ffa050f 100644 --- a/src/components/options_popup.rs +++ b/src/popups/options.rs @@ -1,14 +1,13 @@ -use super::{ - visibility_blocking, CommandBlocking, CommandInfo, Component, - DrawableComponent, EventState, -}; use crate::{ app::Environment, - components::utils::string_width_align, + components::{ + string_width_align, visibility_blocking, CommandBlocking, + CommandInfo, Component, DrawableComponent, EventState, + }, keys::{key_match, SharedKeyConfig}, options::SharedOptions, queue::{InternalEvent, Queue}, - strings::{self}, + strings, ui::{self, style::SharedTheme}, }; use anyhow::Result; @@ -31,7 +30,7 @@ pub enum AppOption { DiffInterhunkLines, } -pub struct OptionsPopupComponent { +pub struct OptionsPopup { selection: AppOption, queue: Queue, visible: bool, @@ -40,7 +39,7 @@ pub struct OptionsPopupComponent { theme: SharedTheme, } -impl OptionsPopupComponent { +impl OptionsPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -256,7 +255,7 @@ impl OptionsPopupComponent { } } -impl DrawableComponent for OptionsPopupComponent { +impl DrawableComponent for OptionsPopup { fn draw( &self, f: &mut Frame, @@ -290,7 +289,7 @@ impl DrawableComponent for OptionsPopupComponent { } } -impl Component for OptionsPopupComponent { +impl Component for OptionsPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/pull.rs b/src/popups/pull.rs similarity index 94% rename from src/components/pull.rs rename to src/popups/pull.rs index e9f42e68..7eb478c8 100644 --- a/src/components/pull.rs +++ b/src/popups/pull.rs @@ -1,11 +1,11 @@ -use super::PushComponent; use crate::{ app::Environment, components::{ - cred::CredComponent, visibility_blocking, CommandBlocking, - CommandInfo, Component, DrawableComponent, EventState, + visibility_blocking, CommandBlocking, CommandInfo, Component, + CredComponent, DrawableComponent, EventState, }, keys::SharedKeyConfig, + popups::PushPopup, queue::{Action, InternalEvent, Queue}, strings, try_or_popup, ui::{self, style::SharedTheme}, @@ -33,7 +33,7 @@ use ratatui::{ }; /// -pub struct PullComponent { +pub struct PullPopup { repo: RepoPathRef, visible: bool, git_fetch: AsyncPull, @@ -46,7 +46,7 @@ pub struct PullComponent { input_cred: CredComponent, } -impl PullComponent { +impl PullPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -197,7 +197,7 @@ impl PullComponent { } } -impl DrawableComponent for PullComponent { +impl DrawableComponent for PullPopup { fn draw( &self, f: &mut Frame, @@ -205,7 +205,7 @@ impl DrawableComponent for PullComponent { ) -> Result<()> { if self.visible { let (state, progress) = - PushComponent::get_progress(&self.progress); + PushPopup::get_progress(&self.progress); let area = ui::centered_rect_absolute(30, 3, f.size()); @@ -234,7 +234,7 @@ impl DrawableComponent for PullComponent { } } -impl Component for PullComponent { +impl Component for PullPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/push.rs b/src/popups/push.rs similarity index 96% rename from src/components/push.rs rename to src/popups/push.rs index 33f44585..b20818d9 100644 --- a/src/components/push.rs +++ b/src/popups/push.rs @@ -1,8 +1,8 @@ use crate::{ app::Environment, components::{ - cred::CredComponent, visibility_blocking, CommandBlocking, - CommandInfo, Component, DrawableComponent, EventState, + visibility_blocking, CommandBlocking, CommandInfo, Component, + CredComponent, DrawableComponent, EventState, }, keys::{key_match, SharedKeyConfig}, queue::{InternalEvent, Queue}, @@ -49,7 +49,7 @@ impl PushComponentModifier { } /// -pub struct PushComponent { +pub struct PushPopup { repo: RepoPathRef, modifier: PushComponentModifier, visible: bool, @@ -64,7 +64,7 @@ pub struct PushComponent { input_cred: CredComponent, } -impl PushComponent { +impl PushPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -226,7 +226,7 @@ impl PushComponent { } } -impl DrawableComponent for PushComponent { +impl DrawableComponent for PushPopup { fn draw( &self, f: &mut Frame, @@ -267,7 +267,7 @@ impl DrawableComponent for PushComponent { } } -impl Component for PushComponent { +impl Component for PushPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/push_tags.rs b/src/popups/push_tags.rs similarity index 94% rename from src/components/push_tags.rs rename to src/popups/push_tags.rs index d2a8f996..73c1af42 100644 --- a/src/components/push_tags.rs +++ b/src/popups/push_tags.rs @@ -1,12 +1,12 @@ use crate::{ app::Environment, components::{ - cred::CredComponent, visibility_blocking, CommandBlocking, - CommandInfo, Component, DrawableComponent, EventState, + visibility_blocking, CommandBlocking, CommandInfo, Component, + CredComponent, DrawableComponent, EventState, }, keys::{key_match, SharedKeyConfig}, queue::{InternalEvent, Queue}, - strings::{self}, + strings, ui::{self, style::SharedTheme}, }; use anyhow::Result; @@ -31,7 +31,7 @@ use ratatui::{ }; /// -pub struct PushTagsComponent { +pub struct PushTagsPopup { repo: RepoPathRef, visible: bool, git_push: AsyncPushTags, @@ -43,7 +43,7 @@ pub struct PushTagsComponent { input_cred: CredComponent, } -impl PushTagsComponent { +impl PushTagsPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -157,7 +157,7 @@ impl PushTagsComponent { } } -impl DrawableComponent for PushTagsComponent { +impl DrawableComponent for PushTagsPopup { fn draw( &self, f: &mut Frame, @@ -194,7 +194,7 @@ impl DrawableComponent for PushTagsComponent { } } -impl Component for PushTagsComponent { +impl Component for PushTagsPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/rename_branch.rs b/src/popups/rename_branch.rs similarity index 88% rename from src/components/rename_branch.rs rename to src/popups/rename_branch.rs index 12411e71..14311544 100644 --- a/src/components/rename_branch.rs +++ b/src/popups/rename_branch.rs @@ -1,7 +1,6 @@ -use super::{ - textinput::TextInputComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, InputType, TextInputComponent, }; use crate::{ app::Environment, @@ -14,7 +13,7 @@ use asyncgit::sync::{self, RepoPathRef}; use crossterm::event::Event; use ratatui::{backend::Backend, layout::Rect, Frame}; -pub struct RenameBranchComponent { +pub struct RenameBranchPopup { repo: RepoPathRef, input: TextInputComponent, branch_ref: Option, @@ -22,7 +21,7 @@ pub struct RenameBranchComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for RenameBranchComponent { +impl DrawableComponent for RenameBranchPopup { fn draw( &self, f: &mut Frame, @@ -34,7 +33,7 @@ impl DrawableComponent for RenameBranchComponent { } } -impl Component for RenameBranchComponent { +impl Component for RenameBranchPopup { fn commands( &self, out: &mut Vec, @@ -87,7 +86,7 @@ impl Component for RenameBranchComponent { } } -impl RenameBranchComponent { +impl RenameBranchPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -99,7 +98,7 @@ impl RenameBranchComponent { &strings::rename_branch_popup_msg(&env.key_config), true, ) - .with_input_type(super::InputType::Singleline), + .with_input_type(InputType::Singleline), branch_ref: None, key_config: env.key_config.clone(), } diff --git a/src/components/reset_popup.rs b/src/popups/reset.rs similarity index 96% rename from src/components/reset_popup.rs rename to src/popups/reset.rs index f384a418..8a32da45 100644 --- a/src/components/reset_popup.rs +++ b/src/popups/reset.rs @@ -1,4 +1,4 @@ -use super::{ +use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, DrawableComponent, EventState, }; @@ -40,7 +40,7 @@ const fn type_to_string( } } -pub struct ResetPopupComponent { +pub struct ResetPopup { queue: Queue, repo: RepoPath, commit: Option, @@ -51,7 +51,7 @@ pub struct ResetPopupComponent { theme: SharedTheme, } -impl ResetPopupComponent { +impl ResetPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -155,7 +155,7 @@ impl ResetPopupComponent { } } -impl DrawableComponent for ResetPopupComponent { +impl DrawableComponent for ResetPopup { fn draw( &self, f: &mut Frame, @@ -189,7 +189,7 @@ impl DrawableComponent for ResetPopupComponent { } } -impl Component for ResetPopupComponent { +impl Component for ResetPopup { fn commands( &self, out: &mut Vec, diff --git a/src/components/revision_files_popup.rs b/src/popups/revision_files.rs similarity index 95% rename from src/components/revision_files_popup.rs rename to src/popups/revision_files.rs index 809c960a..7b3e3643 100644 --- a/src/components/revision_files_popup.rs +++ b/src/popups/revision_files.rs @@ -1,9 +1,6 @@ -use std::path::Path; - -use super::{ - revision_files::RevisionFilesComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, RevisionFilesComponent, }; use crate::{ app::Environment, @@ -18,6 +15,7 @@ use crossterm::event::Event; use ratatui::{ backend::Backend, layout::Rect, widgets::Clear, Frame, }; +use std::path::Path; #[derive(Clone, Debug)] pub struct FileTreeOpen { diff --git a/src/components/stashmsg.rs b/src/popups/stashmsg.rs similarity index 89% rename from src/components/stashmsg.rs rename to src/popups/stashmsg.rs index 55ae57b2..11c87053 100644 --- a/src/components/stashmsg.rs +++ b/src/popups/stashmsg.rs @@ -1,7 +1,6 @@ -use super::{ - textinput::TextInputComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, InputType, TextInputComponent, }; use crate::{ app::Environment, @@ -15,7 +14,7 @@ use asyncgit::sync::{self, RepoPathRef}; use crossterm::event::Event; use ratatui::{backend::Backend, layout::Rect, Frame}; -pub struct StashMsgComponent { +pub struct StashMsgPopup { repo: RepoPathRef, options: StashingOptions, input: TextInputComponent, @@ -23,7 +22,7 @@ pub struct StashMsgComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for StashMsgComponent { +impl DrawableComponent for StashMsgPopup { fn draw( &self, f: &mut Frame, @@ -35,7 +34,7 @@ impl DrawableComponent for StashMsgComponent { } } -impl Component for StashMsgComponent { +impl Component for StashMsgPopup { fn commands( &self, out: &mut Vec, @@ -124,7 +123,7 @@ impl Component for StashMsgComponent { } } -impl StashMsgComponent { +impl StashMsgPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -136,7 +135,7 @@ impl StashMsgComponent { &strings::stash_popup_msg(&env.key_config), true, ) - .with_input_type(super::InputType::Singleline), + .with_input_type(InputType::Singleline), key_config: env.key_config.clone(), repo: env.repo.clone(), } diff --git a/src/components/submodules.rs b/src/popups/submodules.rs similarity index 97% rename from src/components/submodules.rs rename to src/popups/submodules.rs index 1bff7497..6cdd3fa7 100644 --- a/src/components/submodules.rs +++ b/src/popups/submodules.rs @@ -1,10 +1,9 @@ -use super::{ - utils::scroll_vertical::VerticalScroll, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, ScrollType, -}; use crate::{ app::Environment, + components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, ScrollType, VerticalScroll, + }, keys::{key_match, SharedKeyConfig}, queue::{InternalEvent, NeedsUpdate, Queue}, strings, try_or_popup, @@ -31,7 +30,7 @@ use ui::style::SharedTheme; use unicode_truncate::UnicodeTruncateStr; /// -pub struct SubmodulesListComponent { +pub struct SubmodulesListPopup { repo: RepoPathRef, repo_path: String, queue: Queue, @@ -45,7 +44,7 @@ pub struct SubmodulesListComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for SubmodulesListComponent { +impl DrawableComponent for SubmodulesListPopup { fn draw( &self, f: &mut Frame, @@ -103,7 +102,7 @@ impl DrawableComponent for SubmodulesListComponent { } } -impl Component for SubmodulesListComponent { +impl Component for SubmodulesListPopup { fn commands( &self, out: &mut Vec, @@ -245,7 +244,7 @@ impl Component for SubmodulesListComponent { } } -impl SubmodulesListComponent { +impl SubmodulesListPopup { pub fn new(env: &Environment) -> Self { Self { submodules: Vec::new(), diff --git a/src/components/tag_commit.rs b/src/popups/tag_commit.rs similarity index 92% rename from src/components/tag_commit.rs rename to src/popups/tag_commit.rs index e275abb8..3d7f4b47 100644 --- a/src/components/tag_commit.rs +++ b/src/popups/tag_commit.rs @@ -1,7 +1,6 @@ -use super::{ - textinput::TextInputComponent, visibility_blocking, - CommandBlocking, CommandInfo, Component, DrawableComponent, - EventState, +use crate::components::{ + visibility_blocking, CommandBlocking, CommandInfo, Component, + DrawableComponent, EventState, InputType, TextInputComponent, }; use crate::{ app::Environment, @@ -21,7 +20,7 @@ enum Mode { Annotation { tag_name: String }, } -pub struct TagCommitComponent { +pub struct TagCommitPopup { repo: RepoPathRef, mode: Mode, input: TextInputComponent, @@ -30,7 +29,7 @@ pub struct TagCommitComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for TagCommitComponent { +impl DrawableComponent for TagCommitPopup { fn draw( &self, f: &mut Frame, @@ -42,7 +41,7 @@ impl DrawableComponent for TagCommitComponent { } } -impl Component for TagCommitComponent { +impl Component for TagCommitPopup { fn commands( &self, out: &mut Vec, @@ -124,7 +123,7 @@ impl Component for TagCommitComponent { } } -impl TagCommitComponent { +impl TagCommitPopup { /// pub fn new(env: &Environment) -> Self { Self { @@ -135,7 +134,7 @@ impl TagCommitComponent { &strings::tag_popup_name_msg(), true, ) - .with_input_type(super::InputType::Singleline), + .with_input_type(InputType::Singleline), commit_id: None, key_config: env.key_config.clone(), repo: env.repo.clone(), diff --git a/src/components/taglist.rs b/src/popups/taglist.rs similarity index 97% rename from src/components/taglist.rs rename to src/popups/taglist.rs index a2c96e4a..941e8afb 100644 --- a/src/components/taglist.rs +++ b/src/popups/taglist.rs @@ -1,6 +1,6 @@ -use super::{ - utils, visibility_blocking, CommandBlocking, CommandInfo, - Component, DrawableComponent, EventState, +use crate::components::{ + time_to_string, visibility_blocking, CommandBlocking, + CommandInfo, Component, DrawableComponent, EventState, }; use crate::{ app::Environment, @@ -39,7 +39,7 @@ use ratatui::{ use ui::style::SharedTheme; /// -pub struct TagListComponent { +pub struct TagListPopup { repo: RepoPathRef, theme: SharedTheme, queue: Queue, @@ -54,7 +54,7 @@ pub struct TagListComponent { key_config: SharedKeyConfig, } -impl DrawableComponent for TagListComponent { +impl DrawableComponent for TagListPopup { fn draw( &self, f: &mut Frame, @@ -139,7 +139,7 @@ impl DrawableComponent for TagListComponent { } } -impl Component for TagListComponent { +impl Component for TagListPopup { fn commands( &self, out: &mut Vec, @@ -291,7 +291,7 @@ impl Component for TagListComponent { } } -impl TagListComponent { +impl TagListPopup { pub fn new(env: &Environment) -> Self { Self { theme: env.theme.clone(), @@ -477,7 +477,7 @@ impl TagListComponent { .style(self.theme.commit_author(false)), Cell::from(tag.name.clone()) .style(self.theme.text(true, false)), - Cell::from(utils::time_to_string(tag.time, true)) + Cell::from(time_to_string(tag.time, true)) .style(self.theme.commit_time(false)), Cell::from(tag.author.clone()) .style(self.theme.commit_author(false)), diff --git a/src/queue.rs b/src/queue.rs index 170bc68c..d4f9da8e 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,7 +1,8 @@ use crate::{ - components::{ + components::FuzzyFinderTarget, + popups::{ AppOption, BlameFileOpen, FileRevOpen, FileTreeOpen, - FuzzyFinderTarget, InspectCommitOpen, + InspectCommitOpen, }, tabs::StashingOptions, }; diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index a9cff547..33d8998b 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -3,10 +3,10 @@ use crate::{ components::{ visibility_blocking, CommandBlocking, CommandInfo, CommitDetailsComponent, CommitList, Component, - DrawableComponent, EventState, FileTreeOpen, - InspectCommitOpen, + DrawableComponent, EventState, }, keys::{key_match, SharedKeyConfig}, + popups::{FileTreeOpen, InspectCommitOpen}, queue::{InternalEvent, Queue, StackablePopupOpen}, strings::{self, order}, try_or_popup, diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index 5a40cc49..db38f87c 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -3,9 +3,9 @@ use crate::{ components::{ visibility_blocking, CommandBlocking, CommandInfo, CommitList, Component, DrawableComponent, EventState, - InspectCommitOpen, }, keys::{key_match, SharedKeyConfig}, + popups::InspectCommitOpen, queue::{Action, InternalEvent, Queue, StackablePopupOpen}, strings, };