mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 18:40:46 +08:00
lib: Remove unnecessary generic backend parameter
This commit is contained in:
@@ -7,11 +7,8 @@ pub mod theme;
|
||||
pub mod widget;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::io::{self};
|
||||
use std::time::Duration;
|
||||
|
||||
use termion::raw::RawTerminal;
|
||||
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
||||
|
||||
@@ -19,11 +16,8 @@ use super::event::Event;
|
||||
use super::store::State;
|
||||
use super::task::Interrupted;
|
||||
use super::terminal;
|
||||
use super::terminal::TermionBackendExt;
|
||||
use super::ui::widget::Widget;
|
||||
|
||||
type Backend = TermionBackendExt<RawTerminal<io::Stdout>>;
|
||||
|
||||
const RENDERING_TICK_RATE: Duration = Duration::from_millis(250);
|
||||
const INLINE_HEIGHT: usize = 20;
|
||||
|
||||
@@ -72,7 +66,7 @@ impl<A> Frontend<A> {
|
||||
) -> anyhow::Result<Interrupted<P>>
|
||||
where
|
||||
S: State<P>,
|
||||
W: Widget<Backend, State = S, Action = A>,
|
||||
W: Widget<State = S, Action = A>,
|
||||
P: Clone + Send + Sync + Debug,
|
||||
{
|
||||
let mut ticker = tokio::time::interval(RENDERING_TICK_RATE);
|
||||
|
||||
+10
-24
@@ -18,7 +18,7 @@ use ratatui::widgets::{Cell, Row, TableState};
|
||||
use super::theme::style;
|
||||
use super::{layout, span};
|
||||
|
||||
pub type BoxedWidget<B, S, A> = Box<dyn Widget<B, State = S, Action = A>>;
|
||||
pub type BoxedWidget<S, A> = Box<dyn Widget<State = S, Action = A>>;
|
||||
|
||||
pub type UpdateCallback<S> = fn(&S) -> Box<dyn Any>;
|
||||
pub type EventCallback<A> = fn(&dyn Any, UnboundedSender<A>);
|
||||
@@ -97,10 +97,7 @@ pub trait View {
|
||||
/// A `Widget` is a `View` that can be rendered using a specific backend.
|
||||
///
|
||||
/// This is the second trait that you should implement to define a custom `Widget`.
|
||||
pub trait Widget<B>: View
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
pub trait Widget: View {
|
||||
/// Renders a widget to the given frame in the given area.
|
||||
///
|
||||
/// Optional props take precedence over the internal ones.
|
||||
@@ -158,33 +155,27 @@ impl<Id> Default for WindowProps<Id> {
|
||||
|
||||
impl<Id> Properties for WindowProps<Id> {}
|
||||
|
||||
pub struct Window<B, S, A, Id>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
pub struct Window<S, A, Id> {
|
||||
/// Internal base
|
||||
base: BaseView<S, A>,
|
||||
/// Internal properties
|
||||
props: WindowProps<Id>,
|
||||
/// All pages known
|
||||
pages: HashMap<Id, BoxedWidget<B, S, A>>,
|
||||
pages: HashMap<Id, BoxedWidget<S, A>>,
|
||||
}
|
||||
|
||||
impl<B, S, A, Id> Window<B, S, A, Id>
|
||||
impl<S, A, Id> Window<S, A, Id>
|
||||
where
|
||||
B: Backend,
|
||||
Id: Clone + Hash + Eq + PartialEq,
|
||||
{
|
||||
pub fn page(mut self, id: Id, page: BoxedWidget<B, S, A>) -> Self {
|
||||
// self.pages.inse
|
||||
pub fn page(mut self, id: Id, page: BoxedWidget<S, A>) -> Self {
|
||||
self.pages.insert(id, page);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A, Id> View for Window<B, S, A, Id>
|
||||
impl<'a: 'static, S, A, Id> View for Window<S, A, Id>
|
||||
where
|
||||
B: Backend + 'a,
|
||||
Id: Clone + Hash + Eq + PartialEq + 'a,
|
||||
{
|
||||
type Action = A;
|
||||
@@ -236,9 +227,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A, Id> Widget<B> for Window<B, S, A, Id>
|
||||
impl<'a: 'static, S, A, Id> Widget for Window<S, A, Id>
|
||||
where
|
||||
B: Backend + 'a,
|
||||
Id: Clone + Hash + Eq + PartialEq + 'a,
|
||||
{
|
||||
fn render(&self, frame: &mut ratatui::Frame, _area: Rect, props: Option<Box<dyn Any>>) {
|
||||
@@ -343,10 +333,7 @@ impl<S, A> View for Shortcuts<S, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, S, A> Widget<B> for Shortcuts<S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<S, A> Widget for Shortcuts<S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
use ratatui::widgets::Table;
|
||||
|
||||
@@ -615,9 +602,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A, R> Widget<B> for Table<'a, S, A, R>
|
||||
impl<'a: 'static, S, A, R> Widget for Table<'a, S, A, R>
|
||||
where
|
||||
B: Backend,
|
||||
R: ToRow + Clone + Debug + 'static,
|
||||
{
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
|
||||
+12
-30
@@ -111,10 +111,7 @@ impl<'a: 'static, S, A> View for Header<'a, S, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A> Widget<B> for Header<'a, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<'a: 'static, S, A> Widget for Header<'a, S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
let props = props
|
||||
.and_then(HeaderProps::from_boxed_any)
|
||||
@@ -295,10 +292,7 @@ impl<'a, S, A> Footer<'a, S, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A> Widget<B> for Footer<'a, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<'a: 'static, S, A> Widget for Footer<'a, S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
let props = props
|
||||
.and_then(FooterProps::from_boxed_any)
|
||||
@@ -356,46 +350,37 @@ impl ContainerProps {
|
||||
|
||||
impl Properties for ContainerProps {}
|
||||
|
||||
pub struct Container<B, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
pub struct Container<S, A> {
|
||||
/// Internal base
|
||||
base: BaseView<S, A>,
|
||||
/// Internal props
|
||||
props: ContainerProps,
|
||||
/// Container header
|
||||
header: Option<BoxedWidget<B, S, A>>,
|
||||
header: Option<BoxedWidget<S, A>>,
|
||||
/// Content widget
|
||||
content: Option<BoxedWidget<B, S, A>>,
|
||||
content: Option<BoxedWidget<S, A>>,
|
||||
/// Container footer
|
||||
footer: Option<BoxedWidget<B, S, A>>,
|
||||
footer: Option<BoxedWidget<S, A>>,
|
||||
}
|
||||
|
||||
impl<B, S, A> Container<B, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
pub fn header(mut self, header: BoxedWidget<B, S, A>) -> Self {
|
||||
impl<S, A> Container<S, A> {
|
||||
pub fn header(mut self, header: BoxedWidget<S, A>) -> Self {
|
||||
self.header = Some(header);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn content(mut self, content: BoxedWidget<B, S, A>) -> Self {
|
||||
pub fn content(mut self, content: BoxedWidget<S, A>) -> Self {
|
||||
self.content = Some(content);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn footer(mut self, footer: BoxedWidget<B, S, A>) -> Self {
|
||||
pub fn footer(mut self, footer: BoxedWidget<S, A>) -> Self {
|
||||
self.footer = Some(footer);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, S, A> View for Container<B, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<S, A> View for Container<S, A> {
|
||||
type Action = A;
|
||||
type State = S;
|
||||
|
||||
@@ -445,10 +430,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A> Widget<B> for Container<B, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<'a: 'static, S, A> Widget for Container<S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
let props = props
|
||||
.and_then(ContainerProps::from_boxed_any)
|
||||
|
||||
@@ -5,7 +5,7 @@ use termion::event::Key;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use ratatui::layout::{Constraint, Layout};
|
||||
use ratatui::prelude::{Backend, Rect};
|
||||
use ratatui::prelude::Rect;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::{Line, Span};
|
||||
|
||||
@@ -189,10 +189,7 @@ impl<S, A> View for TextField<S, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, S, A> Widget<B> for TextField<S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<S, A> Widget for TextField<S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
let props = props
|
||||
.and_then(TextFieldProps::from_boxed_any)
|
||||
|
||||
@@ -4,7 +4,6 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use termion::event::Key;
|
||||
|
||||
use ratatui::backend::Backend;
|
||||
use ratatui::layout::{Constraint, Layout, Rect};
|
||||
use ratatui::text::Text;
|
||||
|
||||
@@ -205,10 +204,7 @@ impl<'a: 'static, S, A> View for Paragraph<'a, S, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'static, B, S, A> Widget<B> for Paragraph<'a, S, A>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
impl<'a: 'static, S, A> Widget for Paragraph<'a, S, A> {
|
||||
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: Option<Box<dyn Any>>) {
|
||||
let props = props
|
||||
.and_then(ParagraphProps::from_boxed_any)
|
||||
|
||||
Reference in New Issue
Block a user