mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 18:40:46 +08:00
lib: Make use of Share trait
This commit is contained in:
+5
-5
@@ -291,7 +291,7 @@ where
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Interrupted<P>
|
||||
where
|
||||
P: Clone + Send + Sync + Debug,
|
||||
P: Share,
|
||||
{
|
||||
OsSignal,
|
||||
User { payload: Option<P> },
|
||||
@@ -301,14 +301,14 @@ where
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Terminator<P>
|
||||
where
|
||||
P: Clone + Send + Sync + Debug,
|
||||
P: Share,
|
||||
{
|
||||
interrupt_tx: broadcast::Sender<Interrupted<P>>,
|
||||
}
|
||||
|
||||
impl<P> Terminator<P>
|
||||
where
|
||||
P: Clone + Send + Sync + Debug + 'static,
|
||||
P: Share,
|
||||
{
|
||||
/// Create a `Terminator` that stores the sending end of a broadcast channel.
|
||||
pub fn new(interrupt_tx: broadcast::Sender<Interrupted<P>>) -> Self {
|
||||
@@ -327,7 +327,7 @@ where
|
||||
#[cfg(unix)]
|
||||
async fn terminate_by_unix_signal<P>(mut terminator: Terminator<P>)
|
||||
where
|
||||
P: Clone + Send + Sync + Debug + 'static,
|
||||
P: Share,
|
||||
{
|
||||
let mut interrupt_signal = signal(tokio::signal::unix::SignalKind::interrupt())
|
||||
.expect("failed to create interrupt signal stream");
|
||||
@@ -342,7 +342,7 @@ where
|
||||
/// Create a broadcast channel and spawn a task for retrieving the applications' kill signal.
|
||||
pub fn create_termination<P>() -> (Terminator<P>, broadcast::Receiver<Interrupted<P>>)
|
||||
where
|
||||
P: Clone + Send + Sync + Debug + 'static,
|
||||
P: Share,
|
||||
{
|
||||
let (tx, rx) = broadcast::channel(1);
|
||||
let terminator = Terminator::new(tx);
|
||||
|
||||
+5
-4
@@ -1,4 +1,3 @@
|
||||
use std::fmt::Debug;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::thread;
|
||||
@@ -15,9 +14,11 @@ use termion::async_stdin;
|
||||
use termion::input::TermRead;
|
||||
use termion::raw::{IntoRawMode, RawTerminal};
|
||||
|
||||
use ratatui::prelude::*;
|
||||
use ratatui::termion::screen::{AlternateScreen, IntoAlternateScreen};
|
||||
use ratatui::{prelude::*, CompletedFrame};
|
||||
use ratatui::{TerminalOptions, Viewport};
|
||||
use ratatui::{CompletedFrame, TerminalOptions, Viewport};
|
||||
|
||||
use crate::Share;
|
||||
|
||||
use super::event::Event;
|
||||
use super::Interrupted;
|
||||
@@ -173,7 +174,7 @@ impl<W: Write> ratatui::backend::Backend for TermionBackendExt<W> {
|
||||
pub struct StdinReader {}
|
||||
|
||||
impl StdinReader {
|
||||
pub async fn run<P: Clone + Send + Sync + Debug>(
|
||||
pub async fn run<P: Share>(
|
||||
self,
|
||||
event_tx: UnboundedSender<Event>,
|
||||
mut interrupt_rx: broadcast::Receiver<Interrupted<P>>,
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ use crate::store::Update;
|
||||
use crate::terminal::Terminal;
|
||||
use crate::ui::theme::Theme;
|
||||
use crate::ui::{Column, Spacing, ToRow};
|
||||
use crate::Interrupted;
|
||||
use crate::{Interrupted, Share};
|
||||
|
||||
use crate::ui::im::widget::Widget;
|
||||
|
||||
@@ -51,8 +51,8 @@ impl Frontend {
|
||||
) -> anyhow::Result<Interrupted<R>>
|
||||
where
|
||||
S: Update<M, Return = R> + Show<M>,
|
||||
M: Clone,
|
||||
R: Clone + Send + Sync + Debug,
|
||||
M: Share,
|
||||
R: Share,
|
||||
{
|
||||
let mut ticker = tokio::time::interval(RENDERING_TICK_RATE);
|
||||
let mut terminal = Terminal::try_from(viewport)?;
|
||||
|
||||
+5
-4
@@ -1,18 +1,19 @@
|
||||
pub mod widget;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::time::Duration;
|
||||
|
||||
use ratatui::Viewport;
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
|
||||
use ratatui::Viewport;
|
||||
|
||||
use crate::event::Event;
|
||||
use crate::store::Update;
|
||||
use crate::terminal::Terminal;
|
||||
use crate::ui::rm::widget::RenderProps;
|
||||
use crate::ui::rm::widget::Widget;
|
||||
use crate::Interrupted;
|
||||
use crate::Share;
|
||||
|
||||
const RENDERING_TICK_RATE: Duration = Duration::from_millis(250);
|
||||
|
||||
@@ -49,8 +50,8 @@ impl Frontend {
|
||||
) -> anyhow::Result<Interrupted<R>>
|
||||
where
|
||||
S: Update<M, Return = R> + 'static,
|
||||
M: 'static,
|
||||
R: Clone + Send + Sync + Debug,
|
||||
M: Share,
|
||||
R: Share,
|
||||
{
|
||||
let mut ticker = tokio::time::interval(RENDERING_TICK_RATE);
|
||||
let mut terminal = Terminal::try_from(viewport)?;
|
||||
|
||||
Reference in New Issue
Block a user