use std::path::PathBuf;
use crate::types::GeneratedMessage;
use super::super::components::{CodeViewState, DiffViewState, FileTreeState, MessageEditorState};
use super::EmojiMode;
#[derive(Debug, Clone)]
pub struct FileLogEntry {
pub hash: String,
pub short_hash: String,
pub message: String,
pub author: String,
pub relative_time: String,
pub additions: Option<usize>,
pub deletions: Option<usize>,
}
#[derive(Default)]
#[allow(clippy::struct_excessive_bools)]
pub struct ExploreState {
pub current_file: Option<PathBuf>,
pub current_line: usize,
pub selection: Option<(usize, usize)>,
pub selection_anchor: Option<usize>,
pub code_scroll: usize,
pub show_heat_map: bool,
pub file_tree: FileTreeState,
pub code_view: CodeViewState,
pub semantic_blame: Option<super::super::events::SemanticBlameResult>,
pub streaming_blame: Option<String>,
pub blame_loading: bool,
pub file_log: Vec<FileLogEntry>,
pub file_log_selected: usize,
pub file_log_scroll: usize,
pub file_log_loading: bool,
pub global_log: Vec<FileLogEntry>,
pub show_global_log: bool,
pub global_log_loading: bool,
pub pending_file_log: Option<PathBuf>,
}
impl std::fmt::Debug for ExploreState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExploreState")
.field("current_file", &self.current_file)
.field("current_line", &self.current_line)
.field("selection", &self.selection)
.field("code_scroll", &self.code_scroll)
.field("show_heat_map", &self.show_heat_map)
.finish_non_exhaustive()
}
}
#[allow(clippy::struct_excessive_bools)]
pub struct CommitState {
pub messages: Vec<GeneratedMessage>,
pub current_index: usize,
pub custom_instructions: String,
pub selected_file_index: usize,
pub editing_message: bool,
pub generating: bool,
pub use_gitmoji: bool,
pub emoji_mode: EmojiMode,
pub preset: String,
pub file_tree: FileTreeState,
pub diff_view: DiffViewState,
pub message_editor: MessageEditorState,
pub show_all_files: bool,
pub amend_mode: bool,
pub original_message: Option<String>,
}
impl Default for CommitState {
fn default() -> Self {
Self {
messages: Vec::new(),
current_index: 0,
custom_instructions: String::new(),
selected_file_index: 0,
editing_message: false,
generating: false,
use_gitmoji: true,
emoji_mode: EmojiMode::Auto,
preset: "default".to_string(),
file_tree: FileTreeState::new(),
diff_view: DiffViewState::new(),
message_editor: MessageEditorState::new(),
show_all_files: false,
amend_mode: false,
original_message: None,
}
}
}
impl std::fmt::Debug for CommitState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CommitState")
.field("messages_count", &self.messages.len())
.field("current_index", &self.current_index)
.field("selected_file_index", &self.selected_file_index)
.field("editing_message", &self.editing_message)
.field("generating", &self.generating)
.field("amend_mode", &self.amend_mode)
.finish_non_exhaustive()
}
}
pub struct ReviewState {
pub file_tree: FileTreeState,
pub diff_view: DiffViewState,
pub review_content: String,
pub review_scroll: usize,
pub generating: bool,
pub from_ref: String,
pub to_ref: String,
}
impl Default for ReviewState {
fn default() -> Self {
Self {
file_tree: FileTreeState::default(),
diff_view: DiffViewState::default(),
review_content: String::new(),
review_scroll: 0,
generating: false,
from_ref: "HEAD~1".to_string(),
to_ref: "HEAD".to_string(),
}
}
}
impl std::fmt::Debug for ReviewState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ReviewState")
.field("review_content_len", &self.review_content.len())
.field("review_scroll", &self.review_scroll)
.field("generating", &self.generating)
.finish_non_exhaustive()
}
}
#[derive(Debug, Clone)]
pub struct PrCommit {
pub hash: String,
pub message: String,
pub author: String,
}
pub struct PrState {
pub base_branch: String,
pub to_ref: String,
pub commits: Vec<PrCommit>,
pub selected_commit: usize,
pub commit_scroll: usize,
pub file_tree: FileTreeState,
pub diff_view: DiffViewState,
pub pr_content: String,
pub pr_scroll: usize,
pub generating: bool,
}
impl Default for PrState {
fn default() -> Self {
Self {
base_branch: "main".to_string(),
to_ref: "HEAD".to_string(),
commits: Vec::new(),
selected_commit: 0,
commit_scroll: 0,
file_tree: FileTreeState::new(),
diff_view: DiffViewState::new(),
pr_content: String::new(),
pr_scroll: 0,
generating: false,
}
}
}
impl std::fmt::Debug for PrState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PrState")
.field("base_branch", &self.base_branch)
.field("commits_count", &self.commits.len())
.field("selected_commit", &self.selected_commit)
.field("pr_content_len", &self.pr_content.len())
.field("generating", &self.generating)
.finish_non_exhaustive()
}
}
#[derive(Debug, Clone)]
pub struct ChangelogCommit {
pub hash: String,
pub message: String,
pub author: String,
}
#[derive(Debug)]
pub struct ChangelogState {
pub from_ref: String,
pub to_ref: String,
pub commits: Vec<ChangelogCommit>,
pub selected_commit: usize,
pub commit_scroll: usize,
pub diff_view: DiffViewState,
pub changelog_content: String,
pub changelog_scroll: usize,
pub generating: bool,
}
impl Default for ChangelogState {
fn default() -> Self {
Self {
from_ref: "HEAD~1".to_string(),
to_ref: "HEAD".to_string(),
commits: Vec::new(),
selected_commit: 0,
commit_scroll: 0,
diff_view: DiffViewState::new(),
changelog_content: String::new(),
changelog_scroll: 0,
generating: false,
}
}
}
#[derive(Debug)]
pub struct ReleaseNotesState {
pub from_ref: String,
pub to_ref: String,
pub commits: Vec<ChangelogCommit>,
pub selected_commit: usize,
pub commit_scroll: usize,
pub diff_view: DiffViewState,
pub release_notes_content: String,
pub release_notes_scroll: usize,
pub generating: bool,
}
impl Default for ReleaseNotesState {
fn default() -> Self {
Self {
from_ref: "HEAD~1".to_string(),
to_ref: "HEAD".to_string(),
commits: Vec::new(),
selected_commit: 0,
commit_scroll: 0,
diff_view: DiffViewState::new(),
release_notes_content: String::new(),
release_notes_scroll: 0,
generating: false,
}
}
}
#[derive(Debug, Default)]
pub struct ModeStates {
pub explore: ExploreState,
pub commit: CommitState,
pub review: ReviewState,
pub pr: PrState,
pub changelog: ChangelogState,
pub release_notes: ReleaseNotesState,
}