diff --git a/yazi-core/src/notify/message.rs b/yazi-core/src/notify/message.rs index 6610290c..6e611ca6 100644 --- a/yazi-core/src/notify/message.rs +++ b/yazi-core/src/notify/message.rs @@ -19,7 +19,9 @@ pub struct Message { impl From for Message { fn from(opt: NotifyOpt) -> Self { let title = opt.title.lines().next().unwrap_or_default(); - let max_width = opt.content.lines().map(|s| s.width()).max().unwrap_or(0).max(title.width()); + let title_width = title.width() + (opt.level.icon().width() + /* Space */ 1); + + let max_width = opt.content.lines().map(|s| s.width()).max().unwrap_or(0).max(title_width); Self { title: title.to_owned(), diff --git a/yazi-fm/src/notify/layout.rs b/yazi-fm/src/notify/layout.rs index 068011ec..ee4cbfad 100644 --- a/yazi-fm/src/notify/layout.rs +++ b/yazi-fm/src/notify/layout.rs @@ -1,7 +1,5 @@ use ratatui::{buffer::Buffer, layout::{self, Constraint, Offset, Rect}, widgets::{Block, BorderType, Paragraph, Widget, Wrap}}; -use yazi_config::THEME; use yazi_core::notify::Message; -use yazi_proxy::options::NotifyLevel; use crate::Ctx; @@ -49,12 +47,6 @@ impl<'a> Widget for Layout<'a> { let tile = Self::tile(available, ¬ify.messages[..limit]); for (i, m) in notify.messages.iter().enumerate().take(limit) { - let (icon, style) = match m.level { - NotifyLevel::Info => (&THEME.notify.icon_info, THEME.notify.title_info), - NotifyLevel::Warn => (&THEME.notify.icon_warn, THEME.notify.title_warn), - NotifyLevel::Error => (&THEME.notify.icon_error, THEME.notify.title_error), - }; - let mut rect = tile[i].offset(Offset { x: (100 - m.percent) as i32 * tile[i].width as i32 / 100, y: 0 }); rect.width -= rect.x - tile[i].x; @@ -65,9 +57,9 @@ impl<'a> Widget for Layout<'a> { .block( Block::bordered() .border_type(BorderType::Rounded) - .title(format!("{icon} {}", m.title)) - .title_style(style) - .border_style(style), + .title(format!("{} {}", m.level.icon(), m.title)) + .title_style(*m.level.style()) + .border_style(*m.level.style()), ) .render(rect, buf); } diff --git a/yazi-proxy/src/options/notify.rs b/yazi-proxy/src/options/notify.rs index d4b10962..bded3d23 100644 --- a/yazi-proxy/src/options/notify.rs +++ b/yazi-proxy/src/options/notify.rs @@ -2,7 +2,8 @@ use std::{str::FromStr, time::Duration}; use anyhow::bail; use mlua::{ExternalError, ExternalResult}; -use yazi_shared::event::Cmd; +use yazi_config::THEME; +use yazi_shared::{event::Cmd, theme::Style}; pub struct NotifyOpt { pub title: String, @@ -41,7 +42,7 @@ impl<'a> TryFrom> for NotifyOpt { } } -#[derive(Default)] +#[derive(Clone, Copy, Default)] pub enum NotifyLevel { #[default] Info, @@ -49,6 +50,26 @@ pub enum NotifyLevel { Error, } +impl NotifyLevel { + #[inline] + pub fn icon(self) -> &'static str { + match self { + Self::Info => &THEME.notify.icon_info, + Self::Warn => &THEME.notify.icon_warn, + Self::Error => &THEME.notify.icon_error, + } + } + + #[inline] + pub fn style(self) -> &'static Style { + match self { + Self::Info => &THEME.notify.title_info, + Self::Warn => &THEME.notify.title_warn, + Self::Error => &THEME.notify.title_error, + } + } +} + impl FromStr for NotifyLevel { type Err = anyhow::Error;