Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Switch from text to span
Erik Kundt committed 2 years ago
commit 3a435bdd3699f1cc2472696d9e3bf6cf3805a07e
parent 67b38687001805754d48140acda773b2a8b19a84
2 files changed +27 -17
modified src/flux/ui/span.rs
@@ -1,57 +1,57 @@
use ratatui::style::{Style, Stylize};
-
use ratatui::text::Text;
+
use ratatui::text::Span;

use crate::flux::ui::theme::style;

-
pub fn blank() -> Text<'static> {
-
    Text::styled("", Style::default())
+
pub fn blank() -> Span<'static> {
+
    Span::styled("", Style::default())
}

-
pub fn default(content: String) -> Text<'static> {
-
    Text::styled(content, Style::default())
+
pub fn default(content: String) -> Span<'static> {
+
    Span::styled(content, Style::default())
}

-
pub fn primary(content: String) -> Text<'static> {
+
pub fn primary(content: String) -> Span<'static> {
    default(content).style(style::cyan())
}

-
pub fn secondary(content: String) -> Text<'static> {
+
pub fn secondary(content: String) -> Span<'static> {
    default(content).style(style::magenta())
}

-
pub fn ternary(content: String) -> Text<'static> {
+
pub fn ternary(content: String) -> Span<'static> {
    default(content).style(style::blue())
}

-
pub fn positive(content: String) -> Text<'static> {
+
pub fn positive(content: String) -> Span<'static> {
    default(content).style(style::green())
}

-
pub fn negative(content: String) -> Text<'static> {
+
pub fn negative(content: String) -> Span<'static> {
    default(content).style(style::red())
}

-
pub fn badge(content: String) -> Text<'static> {
+
pub fn badge(content: String) -> Span<'static> {
    let content = &format!(" {content} ");
    default(content.to_string()).magenta().reversed()
}

-
pub fn alias(content: String) -> Text<'static> {
+
pub fn alias(content: String) -> Span<'static> {
    secondary(content)
}

-
pub fn labels(content: String) -> Text<'static> {
+
pub fn labels(content: String) -> Span<'static> {
    ternary(content)
}

-
pub fn timestamp(content: String) -> Text<'static> {
+
pub fn timestamp(content: String) -> Span<'static> {
    default(content).style(style::gray().dim())
}

-
pub fn notification_id(content: String) -> Text<'static> {
+
pub fn notification_id(content: String) -> Span<'static> {
    default(content).style(style::gray().dim())
}

-
pub fn notification_type(content: String) -> Text<'static> {
+
pub fn notification_type(content: String) -> Span<'static> {
    default(content).style(style::gray().dim())
}
modified src/flux/ui/widget.rs
@@ -1,5 +1,6 @@
pub mod container;

+
use std::cmp;
use std::fmt::Debug;

use tokio::sync::mpsc::UnboundedSender;
@@ -159,6 +160,15 @@ impl<A> Table<A> {
        });
        self.state.select(selected);
    }
+

+
    pub fn progress(&self, len: usize) -> (usize, usize) {
+
        let step = self
+
            .selected()
+
            .map(|selected| selected.saturating_add(1))
+
            .unwrap_or_default();
+

+
        (cmp::min(step, len), len)
+
    }
}

impl<S, A> Widget<S, A> for Table<A> {
@@ -234,7 +244,7 @@ where
            frame.render_widget(block, area);

            let center = layout::centered_rect(area, 50, 10);
-
            let hint = span::default("Nothing to show".to_string())
+
            let hint = Text::from(span::default("Nothing to show".to_string()))
                .centered()
                .light_magenta()
                .dim();