From 6f0088e194a9fc7c02bf8ddc3e4267f1485cd60c Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 17 Apr 2023 10:02:05 +0200 Subject: [PATCH] Migrate F12 log to AsyncWidget --- src/ui.rs | 14 +++++++++----- src/ui/chat2.rs | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 33bc4a0..eae4f36 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -23,13 +23,13 @@ use toss::{Terminal, WidgetExt}; use crate::config::Config; use crate::logger::{LogMsg, Logger}; use crate::macros::{logging_unwrap, ok_or_return, some_or_return}; +use crate::util::InfallibleExt; use crate::vault::Vault; pub use self::chat::ChatMsg; -use self::chat::ChatState; +use self::chat2::ChatState; use self::input::{key, InputEvent, KeyBindingsList}; use self::rooms::Rooms; -use self::widgets::WidgetWrapper; use self::widgets2::ListState; /// Time to spend batch processing events before redrawing the screen. @@ -44,6 +44,12 @@ pub enum UiError { Io(#[from] io::Error), } +impl From for UiError { + fn from(value: Infallible) -> Self { + Err(value).infallible() + } +} + pub enum UiEvent { GraphemeWidthsChanged, LogChanged, @@ -197,9 +203,7 @@ impl Ui { let widget = match self.mode { Mode::Main => self.rooms.widget().await, - Mode::Log => { - WidgetWrapper::new(self.log_chat.widget(String::new(), true)).boxed_async() - } + Mode::Log => self.log_chat.widget(String::new(), true), }; if let Some(key_bindings_list) = key_bindings_list { diff --git a/src/ui/chat2.rs b/src/ui/chat2.rs index 9ac7409..7567de4 100644 --- a/src/ui/chat2.rs +++ b/src/ui/chat2.rs @@ -141,3 +141,9 @@ pub enum Reaction { }, ComposeError(io::Error), } + +impl Reaction { + pub fn handled(&self) -> bool { + !matches!(self, Self::NotHandled) + } +}