mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-16 08:20:39 +08:00
Switch to published Radicle crates
This commit is contained in:
+25
-23
@@ -1,7 +1,9 @@
|
||||
pub mod format;
|
||||
|
||||
use radicle_surf;
|
||||
|
||||
use cli::terminal::format;
|
||||
use radicle_cli as cli;
|
||||
// use cli::terminal::format;
|
||||
// use radicle_cli as cli;
|
||||
|
||||
use radicle::prelude::Did;
|
||||
use radicle::storage::git::Repository;
|
||||
@@ -10,7 +12,7 @@ use radicle::Profile;
|
||||
|
||||
use radicle::cob::issue::{Issue, IssueId, State as IssueState};
|
||||
use radicle::cob::patch::{Patch, PatchId, State as PatchState};
|
||||
use radicle::cob::{Tag, Timestamp};
|
||||
use radicle::cob::{Label, Timestamp};
|
||||
|
||||
use tuirealm::props::{Color, Style};
|
||||
use tuirealm::tui::text::{Span, Spans};
|
||||
@@ -142,7 +144,7 @@ impl TableItem<8> for PatchItem {
|
||||
let author = Cell::from(format_author(&self.author.did, self.author.is_you))
|
||||
.style(Style::default().fg(theme.colors.browser_list_author));
|
||||
|
||||
let head = Cell::from(format::oid(self.head).item)
|
||||
let head = Cell::from(format::oid(self.head))
|
||||
.style(Style::default().fg(theme.colors.browser_patch_list_head));
|
||||
|
||||
let added = Cell::from(format!("{}", self.added))
|
||||
@@ -151,7 +153,7 @@ impl TableItem<8> for PatchItem {
|
||||
let removed = Cell::from(format!("{}", self.removed))
|
||||
.style(Style::default().fg(theme.colors.browser_patch_list_removed));
|
||||
|
||||
let updated = Cell::from(format::timestamp(&self.timestamp).to_string())
|
||||
let updated = Cell::from(format::timestamp(&self.timestamp))
|
||||
.style(Style::default().fg(theme.colors.browser_list_timestamp));
|
||||
|
||||
[state, id, title, author, head, added, removed, updated]
|
||||
@@ -172,8 +174,8 @@ pub struct IssueItem {
|
||||
title: String,
|
||||
/// Issue author.
|
||||
author: AuthorItem,
|
||||
/// Issue tags.
|
||||
tags: Vec<Tag>,
|
||||
/// Issue labels.
|
||||
labels: Vec<Label>,
|
||||
/// Issue assignees.
|
||||
assignees: Vec<AuthorItem>,
|
||||
/// Time when issue was opened.
|
||||
@@ -197,8 +199,8 @@ impl IssueItem {
|
||||
&self.author
|
||||
}
|
||||
|
||||
pub fn tags(&self) -> &Vec<Tag> {
|
||||
&self.tags
|
||||
pub fn labels(&self) -> &Vec<Label> {
|
||||
&self.labels
|
||||
}
|
||||
|
||||
pub fn assignees(&self) -> &Vec<AuthorItem> {
|
||||
@@ -222,12 +224,12 @@ impl From<(&Profile, &Repository, IssueId, Issue)> for IssueItem {
|
||||
did: issue.author().id,
|
||||
is_you: *issue.author().id == *profile.did(),
|
||||
},
|
||||
tags: issue.tags().cloned().collect(),
|
||||
labels: issue.labels().cloned().collect(),
|
||||
assignees: issue
|
||||
.assigned()
|
||||
.map(|did| AuthorItem {
|
||||
did,
|
||||
is_you: did == profile.did(),
|
||||
did: *did,
|
||||
is_you: *did == profile.did(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
timestamp: issue.timestamp(),
|
||||
@@ -249,8 +251,8 @@ impl TableItem<7> for IssueItem {
|
||||
let author = Cell::from(format_author(&self.author.did, self.author.is_you))
|
||||
.style(Style::default().fg(theme.colors.browser_list_author));
|
||||
|
||||
let tags = Cell::from(format_tags(&self.tags))
|
||||
.style(Style::default().fg(theme.colors.browser_list_tags));
|
||||
let labels = Cell::from(format_labels(&self.labels))
|
||||
.style(Style::default().fg(theme.colors.browser_list_labels));
|
||||
|
||||
let assignees = self
|
||||
.assignees
|
||||
@@ -260,10 +262,10 @@ impl TableItem<7> for IssueItem {
|
||||
let assignees = Cell::from(format_assignees(&assignees))
|
||||
.style(Style::default().fg(theme.colors.browser_list_author));
|
||||
|
||||
let opened = Cell::from(format::timestamp(&self.timestamp).to_string())
|
||||
let opened = Cell::from(format::timestamp(&self.timestamp))
|
||||
.style(Style::default().fg(theme.colors.browser_list_timestamp));
|
||||
|
||||
[state, id, title, author, tags, assignees, opened]
|
||||
[state, id, title, author, labels, assignees, opened]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +291,7 @@ impl ListItem for IssueItem {
|
||||
Style::default().fg(theme.colors.property_divider_fg),
|
||||
),
|
||||
Span::styled(
|
||||
format::timestamp(&self.timestamp).to_string(),
|
||||
format::timestamp(&self.timestamp),
|
||||
Style::default().fg(theme.colors.browser_list_timestamp),
|
||||
),
|
||||
]),
|
||||
@@ -320,7 +322,7 @@ pub fn format_author(did: &Did, is_you: bool) -> String {
|
||||
if is_you {
|
||||
format!("{} (you)", format::did(did))
|
||||
} else {
|
||||
format!("{}", format::did(did))
|
||||
format::did(did)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,14 +333,14 @@ pub fn format_issue_state(state: &IssueState) -> (String, Color) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_tags(tags: &[Tag]) -> String {
|
||||
pub fn format_labels(labels: &[Label]) -> String {
|
||||
let mut output = String::new();
|
||||
let mut tags = tags.iter().peekable();
|
||||
let mut labels = labels.iter().peekable();
|
||||
|
||||
while let Some(tag) = tags.next() {
|
||||
output.push_str(&tag.to_string());
|
||||
while let Some(label) = labels.next() {
|
||||
output.push_str(&label.to_string());
|
||||
|
||||
if tags.peek().is_some() {
|
||||
if labels.peek().is_some() {
|
||||
output.push(',');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
use radicle::cob::{ObjectId, Timestamp};
|
||||
use radicle::prelude::Did;
|
||||
|
||||
/// Format a git Oid.
|
||||
pub fn oid(oid: impl Into<radicle::git::Oid>) -> String {
|
||||
format!("{:.7}", oid.into())
|
||||
}
|
||||
|
||||
/// Format a COB id.
|
||||
pub fn cob(id: &ObjectId) -> String {
|
||||
format!("{:.7}", id.to_string())
|
||||
}
|
||||
|
||||
/// Format a DID.
|
||||
pub fn did(did: &Did) -> String {
|
||||
let nid = did.as_key().to_human();
|
||||
format!("{}…{}", &nid[..7], &nid[nid.len() - 7..])
|
||||
}
|
||||
|
||||
/// Format a timestamp.
|
||||
pub fn timestamp(time: &Timestamp) -> String {
|
||||
let fmt = timeago::Formatter::new();
|
||||
let now = Timestamp::now();
|
||||
let duration = std::time::Duration::from_secs(now.as_secs() - time.as_secs());
|
||||
|
||||
fmt.convert(duration)
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ pub struct Colors {
|
||||
pub browser_list_title: Color,
|
||||
pub browser_list_description: Color,
|
||||
pub browser_list_author: Color,
|
||||
pub browser_list_tags: Color,
|
||||
pub browser_list_labels: Color,
|
||||
pub browser_list_comments: Color,
|
||||
pub browser_list_timestamp: Color,
|
||||
pub browser_patch_list_head: Color,
|
||||
@@ -94,7 +94,7 @@ pub fn default_dark() -> Theme {
|
||||
browser_list_title: COLOR_DEFAULT_FG,
|
||||
browser_list_description: COLOR_DEFAULT_DARK,
|
||||
browser_list_author: Color::Gray,
|
||||
browser_list_tags: Color::LightBlue,
|
||||
browser_list_labels: Color::LightBlue,
|
||||
browser_list_comments: COLOR_DEFAULT_DARK_FG,
|
||||
browser_list_timestamp: COLOR_DEFAULT_DARK,
|
||||
browser_patch_list_head: Color::LightBlue,
|
||||
|
||||
@@ -106,10 +106,10 @@ impl IssueHeader {
|
||||
common::label(&id.to_string()).foreground(theme.colors.browser_list_description),
|
||||
);
|
||||
|
||||
let tags = Property::new(
|
||||
let labels = Property::new(
|
||||
common::label("Tags").foreground(theme.colors.property_name_fg),
|
||||
common::label(&cob::format_tags(item.tags()))
|
||||
.foreground(theme.colors.browser_list_tags),
|
||||
common::label(&cob::format_labels(item.labels()))
|
||||
.foreground(theme.colors.browser_list_labels),
|
||||
);
|
||||
|
||||
let assignees = Property::new(
|
||||
@@ -135,7 +135,7 @@ impl IssueHeader {
|
||||
Widget::new(title),
|
||||
Widget::new(issue_id),
|
||||
Widget::new(author),
|
||||
Widget::new(tags),
|
||||
Widget::new(labels),
|
||||
Widget::new(assignees),
|
||||
Widget::new(state),
|
||||
],
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use radicle::cob::patch::{Patch, PatchId};
|
||||
|
||||
use radicle_cli::terminal::format;
|
||||
|
||||
use tuirealm::command::{Cmd, CmdResult};
|
||||
use tuirealm::tui::layout::Rect;
|
||||
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
|
||||
@@ -108,7 +106,7 @@ pub fn context(context: &Context, theme: &Theme, patch: (PatchId, Patch)) -> Wid
|
||||
let (_, rev) = patch.latest();
|
||||
let is_you = *patch.author().id() == context.profile().did();
|
||||
|
||||
let id = format::cob(&id);
|
||||
let id = cob::format::cob(&id);
|
||||
let title = patch.title();
|
||||
let author = cob::format_author(patch.author().id(), is_you);
|
||||
let comments = rev.discussion().len();
|
||||
|
||||
Reference in New Issue
Block a user