yazi_core/notify/
option.rs1use std::time::Duration;
2
3use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value};
4use serde::{Deserialize, Serialize};
5use serde_with::{DurationSecondsWithFrac, serde_as};
6use yazi_binding::SER_OPT;
7use yazi_shared::event::ActionCow;
8
9use crate::notify::MessageLevel;
10
11#[serde_as]
12#[derive(Clone, Debug, Deserialize, Serialize)]
13pub struct MessageOpt {
14 #[serde(alias = "0")]
15 pub content: String,
16 #[serde(alias = "1")]
17 pub title: String,
18 #[serde(default)]
19 pub level: MessageLevel,
20 #[serde_as(as = "DurationSecondsWithFrac<f64>")]
21 pub timeout: Duration,
22}
23
24impl TryFrom<ActionCow> for MessageOpt {
25 type Error = anyhow::Error;
26
27 fn try_from(a: ActionCow) -> Result<Self, Self::Error> { Ok(a.deserialize()?) }
28}
29
30impl FromLua for MessageOpt {
31 fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { lua.from_value(value) }
32}
33
34impl IntoLua for MessageOpt {
35 fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value_with(&self, SER_OPT) }
36}