diff --git a/asyncgit/src/sync/branch.rs b/asyncgit/src/sync/branch.rs index ec46cf79..6c3310e8 100644 --- a/asyncgit/src/sync/branch.rs +++ b/asyncgit/src/sync/branch.rs @@ -43,6 +43,8 @@ pub struct BranchForDisplay { pub top_commit: CommitId, /// pub is_head: bool, + /// + pub has_upstream: bool, } /// Used to return only the nessessary information for displaying a branch @@ -67,6 +69,7 @@ pub fn get_branches_to_display( )?, top_commit: top_commit.id().into(), is_head: branch.is_head(), + has_upstream: branch.upstream().is_ok(), }) }) .filter_map(Result::ok) diff --git a/src/components/select_branch.rs b/src/components/select_branch.rs index d0f69845..297aab5c 100644 --- a/src/components/select_branch.rs +++ b/src/components/select_branch.rs @@ -228,7 +228,7 @@ impl SelectBranchComponent { } /// Get all the names of the branches in the repo pub fn get_branch_names() -> Result> { - get_branches_to_display(CWD).map_err(anyhow::Error::new) + Ok(get_branches_to_display(CWD)?) } /// @@ -325,70 +325,47 @@ impl SelectBranchComponent { branch_name += "..."; } + let selected = + self.selection as usize - self.scroll_top.get() == i; + let is_head_str = if displaybranch.is_head { "*" } else { " " }; + let has_upstream_str = if displaybranch.has_upstream { + "\u{2191}" + } else { + " " + }; - txt.push(Spans::from( - if self.selection as usize - self.scroll_top.get() - == i - { - vec![ - Span::styled( - format!("{} ", is_head_str), - theme.commit_author(true), - ), - Span::styled( - format!( - ">{:w$} ", - branch_name, - w = branch_name_length - ), - theme.commit_author(true), - ), - Span::styled( - format!( - "{} ", - displaybranch - .top_commit - .get_short_string() - ), - theme.commit_hash(true), - ), - Span::styled( - commit_message.to_string(), - theme.text(true, true), - ), - ] - } else { - vec![ - Span::styled( - format!("{} ", is_head_str), - theme.commit_author(false), - ), - Span::styled( - format!( - " {:w$} ", - branch_name, - w = branch_name_length - ), - theme.commit_author(false), - ), - Span::styled( - format!( - "{} ", - displaybranch - .top_commit - .get_short_string() - ), - theme.commit_hash(false), - ), - Span::styled( - commit_message.to_string(), - theme.text(true, false), - ), - ] - }, - )); + let span_prefix = Span::styled( + format!("{}{} ", is_head_str, has_upstream_str), + theme.commit_author(selected), + ); + let span_hash = Span::styled( + format!( + "{} ", + displaybranch.top_commit.get_short_string() + ), + theme.commit_hash(selected), + ); + let span_msg = Span::styled( + commit_message.to_string(), + theme.text(true, selected), + ); + let span_name = Span::styled( + format!( + "{:w$} ", + branch_name, + w = branch_name_length + ), + theme.branch(selected, displaybranch.is_head), + ); + + txt.push(Spans::from(vec![ + span_prefix, + span_name, + span_hash, + span_msg, + ])); } Ok(Text::from(txt)) diff --git a/src/ui/style.rs b/src/ui/style.rs index 390c5767..8708dc01 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -70,6 +70,20 @@ impl Theme { } } + pub fn branch(&self, selected: bool, head: bool) -> Style { + let branch = if head { + Style::default().add_modifier(Modifier::BOLD) + } else { + Style::default() + }; + + if selected { + branch.patch(Style::default().bg(self.selection_bg)) + } else { + branch + } + } + pub fn tab(&self, selected: bool) -> Style { if selected { self.text(true, false)