mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-29 06:20:28 +08:00
lib: Switch from text to span
This commit is contained in:
+16
-16
@@ -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())
|
||||
}
|
||||
|
||||
+11
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user