Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new [notify] section to the theme.toml to configure the notify component's style #749

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions yazi-config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ footer = { fg = "black", bg = "white" }
# : }}}


# : Notify {{{

[notify]
title_info = { fg = "green" }
title_warn = { bg = "yellow" }
title_error = { fg = "red" }

# Icons
icon_info = ""
icon_warn = ""
icon_error = ""

# : }}}


# : File-specific styles {{{

[filetype]
Expand Down
12 changes: 12 additions & 0 deletions yazi-config/src/theme/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Theme {
pub tasks: Tasks,
pub which: Which,
pub help: Help,
pub notify: Notify,

// File-specific styles
#[serde(rename = "filetype", deserialize_with = "Filetype::deserialize", skip_serializing)]
Expand Down Expand Up @@ -160,3 +161,14 @@ pub struct Help {
pub hovered: Style,
pub footer: Style,
}

#[derive(Deserialize, Serialize)]
pub struct Notify {
pub title_info: Style,
pub title_warn: Style,
pub title_error: Style,

pub icon_info: String,
pub icon_warn: String,
pub icon_error: String,
}
9 changes: 5 additions & 4 deletions yazi-fm/src/notify/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::rc::Rc;

use ratatui::{buffer::Buffer, layout::{self, Constraint, Offset, Rect}, style::{Style, Stylize}, widgets::{Block, BorderType, Paragraph, Widget, Wrap}};
use ratatui::{buffer::Buffer, layout::{self, Constraint, Offset, Rect}, widgets::{Block, BorderType, Paragraph, Widget, Wrap}};
use yazi_config::THEME;
use yazi_core::notify::{Level, Message};

use crate::{widgets::Clear, Ctx};
Expand Down Expand Up @@ -42,9 +43,9 @@ impl<'a> Widget for Layout<'a> {

for (i, m) in notify.messages.iter().enumerate().take(limit) {
let (icon, style) = match m.level {
Level::Info => ("", Style::default().green()),
Level::Warn => ("", Style::default().yellow()),
Level::Error => ("", Style::default().red()),
Level::Info => (&THEME.notify.icon_info, THEME.notify.title_info),
Level::Warn => (&THEME.notify.icon_warn, THEME.notify.title_warn),
Level::Error => (&THEME.notify.icon_error, THEME.notify.title_error),
};

let mut rect =
Expand Down