Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
tui: Add ui wrapper for patches
Erik Kundt committed 3 years ago
commit 3358c264ed568d2d2848f5bfb16dc8774126cee7
parent 0b6e32a351302bf69a60fce39c4d66c6293abe60
4 files changed +89 -0
modified radicle-tui/Cargo.toml
@@ -13,6 +13,7 @@ path = "src/main.rs"
[dependencies]
anyhow = { version = "1" }
lexopt = { version = "0.2" }
+
timeago = { version = "0.4.1" }
tuirealm = { version = "1.8.0", default-features = false, features = [ "with-termion" ] }
tui-realm-stdlib = { version = "1.2.0", default-features = false, features = [ "with-termion" ] }

added radicle-tui/src/ui/cob.rs
@@ -0,0 +1 @@
+
pub mod patch;
added radicle-tui/src/ui/cob/patch.rs
@@ -0,0 +1,77 @@
+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
+

+
use radicle::Profile;
+
use timeago;
+

+
use radicle::cob::patch::{Patch, PatchId};
+

+
use tuirealm::props::{Color, TextSpan};
+

+
use crate::ui::components::list::List;
+
use crate::ui::theme::Theme;
+

+
fn format_status(_patch: &Patch) -> String {
+
    String::from(" ⏺ ")
+
}
+

+
fn format_title(patch: &Patch) -> String {
+
    patch.title().to_string()
+
}
+

+
fn format_author(patch: &Patch, profile: &Profile) -> String {
+
    let author_did = patch.author().id();
+
    let start = &author_did.to_human()[0..4];
+
    let end = &author_did.to_human()[43..47];
+

+
    if *author_did == profile.did() {
+
        format!("did:key:{}...{} (you)", start, end)
+
    } else {
+
        format!("did:key:{}...{}", start, end)
+
    }
+
}
+

+
fn format_tags(patch: &Patch) -> String {
+
    format!("{:?}", patch.tags().collect::<Vec<_>>())
+
}
+

+
fn format_timestamp(patch: &Patch) -> String {
+
    let fmt = timeago::Formatter::new();
+
    let now = SystemTime::now()
+
        .duration_since(UNIX_EPOCH)
+
        .unwrap()
+
        .as_secs();
+

+
    fmt.convert(Duration::from_secs(now - patch.timestamp().as_secs()))
+
}
+

+
fn format_comments(patch: &Patch) -> String {
+
    let (_, revision) = patch.latest().unwrap();
+
    let count = revision.discussion().len();
+
    format!("{}", count)
+
}
+

+
impl List for (PatchId, Patch) {
+
    fn row(&self, theme: &Theme, profile: &Profile) -> Vec<TextSpan> {
+
        let (_, patch) = self;
+

+
        let status = format_status(patch);
+
        let status = TextSpan::from(status).fg(Color::Green);
+

+
        let title = format_title(patch);
+
        let title = TextSpan::from(title).fg(theme.colors.browser_patch_list_title);
+

+
        let author = format_author(patch, profile);
+
        let author = TextSpan::from(author).fg(theme.colors.browser_patch_list_author);
+

+
        let tags = format_tags(patch);
+
        let tags = TextSpan::from(tags).fg(theme.colors.browser_patch_list_tags);
+

+
        let comments = format_comments(patch);
+
        let comments = TextSpan::from(comments).fg(theme.colors.browser_patch_list_comments);
+

+
        let timestamp = format_timestamp(patch);
+
        let timestamp = TextSpan::from(timestamp).fg(theme.colors.browser_patch_list_timestamp);
+

+
        vec![status, title, author, tags, comments, timestamp]
+
    }
+
}
modified radicle-tui/src/ui/theme.rs
@@ -13,6 +13,11 @@ pub struct Colors {
    pub shortcut_short_fg: Color,
    pub shortcut_long_fg: Color,
    pub shortcutbar_divider_fg: Color,
+
    pub browser_patch_list_title: Color,
+
    pub browser_patch_list_author: Color,
+
    pub browser_patch_list_tags: Color,
+
    pub browser_patch_list_comments: Color,
+
    pub browser_patch_list_timestamp: Color,
}

#[derive(Debug)]
@@ -59,6 +64,11 @@ pub fn default_dark() -> Theme {
            shortcut_short_fg: Color::Rgb(100, 100, 100),
            shortcut_long_fg: Color::Rgb(70, 70, 70),
            shortcutbar_divider_fg: Color::Rgb(70, 70, 70),
+
            browser_patch_list_title: Color::Rgb(200, 200, 200),
+
            browser_patch_list_author: Color::Rgb(85, 85, 255),
+
            browser_patch_list_tags: Color::Rgb(220, 140, 40),
+
            browser_patch_list_comments: Color::Rgb(150, 150, 150),
+
            browser_patch_list_timestamp: Color::Rgb(100, 100, 100),
        },
        icons: Icons {
            property_divider: '∙',