mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
fix!: make ui.Style immutable (#3862)
This commit is contained in:
parent
354cdef907
commit
f6408656b4
35 changed files with 256 additions and 138 deletions
|
|
@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
|
||||
- Upgrade Lua to 5.5 ([#3633])
|
||||
- Change preset <kbd>t</kbd> for creating tabs to <kbd>t</kbd> ⇒ <kbd>t</kbd> to avoid conflict with new <kbd>t</kbd> ⇒ <kbd>r</kbd> for renaming tabs ([#3666])
|
||||
- Make `ui.Style` immutable ([#3862])
|
||||
- Remove `title_format` in favor of new `ind-app-title` DDS event for flexible title customization ([#3684])
|
||||
- Remove `micro_workers` and `macro_workers` in favor of finer control over concurrent workers ([#3661])
|
||||
|
||||
|
|
@ -1697,3 +1698,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
[#3813]: https://github.com/sxyazi/yazi/pull/3813
|
||||
[#3846]: https://github.com/sxyazi/yazi/pull/3846
|
||||
[#3854]: https://github.com/sxyazi/yazi/pull/3854
|
||||
[#3862]: https://github.com/sxyazi/yazi/pull/3862
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, Value};
|
||||
use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, UserDataMethods, Value};
|
||||
use paste::paste;
|
||||
|
||||
use super::{Lives, PtrCell};
|
||||
|
|
@ -38,7 +38,7 @@ impl Core {
|
|||
}
|
||||
|
||||
impl UserData for Core {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_meta_method_mut(MetaMethod::Index, |lua, me, key: mlua::String| {
|
||||
macro_rules! reuse {
|
||||
($key:ident, $value:expr) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, IntoLuaMulti, UserData, Value};
|
||||
use mlua::{ExternalError, FromLua, IntoLua, IntoLuaMulti, UserData, UserDataMethods, Value};
|
||||
use yazi_codegen::FromLuaOwned;
|
||||
|
||||
use crate::Error;
|
||||
|
|
@ -8,7 +8,7 @@ pub struct MpscTx<T: FromLua + 'static>(pub tokio::sync::mpsc::Sender<T>);
|
|||
pub struct MpscRx<T: IntoLua + 'static>(pub tokio::sync::mpsc::Receiver<T>);
|
||||
|
||||
impl<T: FromLua> UserData for MpscTx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method("send", |lua, me, value: Value| async move {
|
||||
match me.0.send(T::from_lua(value, &lua)?).await {
|
||||
Ok(()) => true.into_lua_multi(&lua),
|
||||
|
|
@ -19,7 +19,7 @@ impl<T: FromLua> UserData for MpscTx<T> {
|
|||
}
|
||||
|
||||
impl<T: IntoLua + 'static> UserData for MpscRx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
||||
match me.0.recv().await {
|
||||
Some(value) => (value, true).into_lua_multi(&lua),
|
||||
|
|
@ -34,7 +34,7 @@ pub struct MpscUnboundedTx<T: FromLua + 'static>(pub tokio::sync::mpsc::Unbounde
|
|||
pub struct MpscUnboundedRx<T: IntoLua + 'static>(pub tokio::sync::mpsc::UnboundedReceiver<T>);
|
||||
|
||||
impl<T: FromLua> UserData for MpscUnboundedTx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_method("send", |lua, me, value: Value| match me.0.send(T::from_lua(value, lua)?) {
|
||||
Ok(()) => true.into_lua_multi(lua),
|
||||
Err(e) => (false, Error::custom(e.to_string())).into_lua_multi(lua),
|
||||
|
|
@ -43,7 +43,7 @@ impl<T: FromLua> UserData for MpscUnboundedTx<T> {
|
|||
}
|
||||
|
||||
impl<T: IntoLua + 'static> UserData for MpscUnboundedRx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
||||
match me.0.recv().await {
|
||||
Some(value) => (value, true).into_lua_multi(&lua),
|
||||
|
|
@ -58,7 +58,7 @@ pub struct OneshotTx<T: FromLua + 'static>(pub Option<tokio::sync::oneshot::Send
|
|||
pub struct OneshotRx<T: IntoLua + 'static>(pub Option<tokio::sync::oneshot::Receiver<T>>);
|
||||
|
||||
impl<T: FromLua> UserData for OneshotTx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_method_mut("send", |lua, me, value: Value| {
|
||||
let Some(tx) = me.0.take() else {
|
||||
return Err("Oneshot sender already used".into_lua_err());
|
||||
|
|
@ -72,7 +72,7 @@ impl<T: FromLua> UserData for OneshotTx<T> {
|
|||
}
|
||||
|
||||
impl<T: IntoLua + 'static> UserData for OneshotRx<T> {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
||||
let Some(rx) = me.0.take() else {
|
||||
return Err("Oneshot receiver already used".into_lua_err());
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use mlua::{ExternalError, ExternalResult, FromLua, Lua, UserData, Value};
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Color(pub ratatui::style::Color);
|
||||
|
||||
impl FromLua for Color {
|
||||
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
|
||||
Ok(Self(match value {
|
||||
Value::String(s) => ratatui::style::Color::from_str(&s.to_str()?).into_lua_err()?,
|
||||
Value::UserData(ud) => ud.borrow::<Self>()?.0,
|
||||
_ => Err("expected a Color".into_lua_err())?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl UserData for Color {}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::{Borders, Widget};
|
||||
|
||||
use super::{Area, Edge};
|
||||
|
|
@ -77,7 +77,7 @@ impl Widget for &Bar {
|
|||
}
|
||||
|
||||
impl UserData for Bar {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
crate::impl_style_method!(methods, style);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::{Borders, Widget};
|
||||
|
||||
use super::{Area, Edge};
|
||||
|
|
@ -75,7 +75,7 @@ impl Widget for &Border {
|
|||
}
|
||||
|
||||
impl UserData for Border {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
crate::impl_style_method!(methods, style);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
use super::Area;
|
||||
|
|
@ -38,7 +38,7 @@ impl Widget for &Clear {
|
|||
}
|
||||
|
||||
impl UserData for Clear {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
yazi-binding/src/elements/color.rs
Normal file
30
yazi-binding/src/elements/color.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Color(pub ratatui::style::Color);
|
||||
|
||||
impl Color {
|
||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||
let new = lua.create_function(|_, (_, color): (Table, Color)| Ok(color))?;
|
||||
|
||||
let color = lua.create_table()?;
|
||||
color.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||
|
||||
color.into_lua(lua)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromLua for Color {
|
||||
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
|
||||
Ok(Self(match value {
|
||||
Value::Nil => ratatui::style::Color::Reset,
|
||||
Value::String(s) => ratatui::style::Color::from_str(&s.to_str()?).into_lua_err()?,
|
||||
Value::UserData(ud) => ud.borrow::<Self>()?.0,
|
||||
_ => Err("expected a Color".into_lua_err())?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl UserData for Color {}
|
||||
|
|
@ -11,6 +11,7 @@ pub fn compose(p_get: ComposerGet, p_set: ComposerSet) -> Composer<ComposerGet,
|
|||
b"Bar" => super::Bar::compose(lua)?,
|
||||
b"Border" => super::Border::compose(lua)?,
|
||||
b"Clear" => super::Clear::compose(lua)?,
|
||||
b"Color" => super::Color::compose(lua)?,
|
||||
b"Constraint" => super::Constraint::compose(lua)?,
|
||||
b"Edge" => super::Edge::compose(lua)?,
|
||||
b"Gauge" => super::Gauge::compose(lua)?,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
use super::{Area, Text};
|
||||
|
|
@ -43,7 +43,7 @@ impl Widget for &List {
|
|||
}
|
||||
|
||||
impl UserData for List {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
yazi_macro::mod_flat!(align area bar border cell clear constraint edge elements gauge layout line list pad pos rect renderable row span table text wrap);
|
||||
yazi_macro::mod_flat!(align area bar border cell clear color constraint edge elements gauge layout line list pad pos rect renderable row span table text wrap);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{ops::Deref, str::FromStr};
|
||||
|
||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use yazi_shim::strum::IntoStr;
|
||||
|
||||
use super::Pad;
|
||||
|
|
@ -90,7 +90,7 @@ impl UserData for Pos {
|
|||
fields.add_field_method_get("h", |_, me| Ok(me.offset.height));
|
||||
}
|
||||
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_function_mut("pad", |_, (ud, pad): (AnyUserData, Pad)| {
|
||||
ud.borrow_mut::<Self>()?.pad = pad;
|
||||
Ok(ud)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
|
||||
use super::Pad;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ impl UserData for Rect {
|
|||
fields.add_field_method_get("bottom", |_, me| Ok(me.bottom()));
|
||||
}
|
||||
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad)));
|
||||
methods.add_method("contains", |_, me, Self(rect)| Ok(me.contains(rect.into())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
|
||||
use super::Cell;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ impl FromLua for Row {
|
|||
}
|
||||
|
||||
impl UserData for Row {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_style_method!(methods, style);
|
||||
|
||||
methods.add_function_mut("height", |_, (ud, value): (AnyUserData, u16)| {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, UserData, Value};
|
||||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::{StatefulWidget, Widget};
|
||||
|
||||
use super::{Area, Row};
|
||||
|
|
@ -105,7 +105,7 @@ impl Widget for &Table {
|
|||
}
|
||||
|
||||
impl UserData for Table {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
|
||||
methods.add_function_mut("header", |_, (ud, header): (AnyUserData, Row)| {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{any::TypeId, mem};
|
||||
|
||||
use ansi_to_tui::IntoText;
|
||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
use super::{Area, Line, Span, Wrap};
|
||||
|
|
@ -119,7 +119,7 @@ impl FromLua for Text {
|
|||
}
|
||||
|
||||
impl UserData for Text {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_area_method!(methods);
|
||||
crate::impl_style_method!(methods, inner.style);
|
||||
crate::impl_style_shorthands!(methods, inner.style);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use mlua::{MetaMethod, UserData};
|
||||
use mlua::{MetaMethod, UserData, UserDataMethods};
|
||||
|
||||
pub struct ImageInfo(yazi_adapter::ImageInfo);
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ impl UserData for ImageInfo {
|
|||
struct ImageFormat(yazi_adapter::ImageFormat);
|
||||
|
||||
impl UserData for ImageFormat {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| {
|
||||
use yazi_adapter::ImageFormat as F;
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ impl UserData for ImageFormat {
|
|||
struct ImageColor(yazi_adapter::ImageColor);
|
||||
|
||||
impl UserData for ImageColor {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| {
|
||||
use yazi_adapter::ImageColor as C;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use mlua::{MetaMethod, UserData};
|
||||
use mlua::{MetaMethod, UserData, UserDataMethods};
|
||||
use yazi_shim::strum::IntoStr;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
|
@ -9,7 +9,7 @@ impl From<yazi_shared::Layer> for Layer {
|
|||
}
|
||||
|
||||
impl UserData for Layer {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.0.into_str()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ mod macros;
|
|||
|
||||
yazi_macro::mod_pub!(elements process);
|
||||
|
||||
yazi_macro::mod_flat!(access calculator cha chan chord_cow color composer error fd file handle icon id image input iter layer mouse path permit range runtime scheme stage style url utils);
|
||||
yazi_macro::mod_flat!(access calculator cha chan chord_cow composer error fd file handle icon id image input iter layer mouse path permit range runtime scheme stage style url utils);
|
||||
|
|
|
|||
|
|
@ -117,37 +117,39 @@ macro_rules! impl_style_method {
|
|||
macro_rules! impl_style_shorthands {
|
||||
($methods:ident, $($field:tt).+) => {
|
||||
$methods.add_function_mut("fg", |lua, (ud, value): (mlua::AnyUserData, mlua::Value)| {
|
||||
use $crate::elements::Color;
|
||||
use mlua::FromLua;
|
||||
use ratatui::style::Modifier;
|
||||
|
||||
let me = &mut ud.borrow_mut::<Self>()?.$($field).+;
|
||||
match value {
|
||||
mlua::Value::Boolean(true) if me.add_modifier.contains(Modifier::REVERSED) && !me.sub_modifier.contains(Modifier::REVERSED) => {
|
||||
me.bg.map($crate::Color).into_lua(lua)
|
||||
mlua::Value::Boolean(true) if me.has_modifier(Modifier::REVERSED) => {
|
||||
me.bg.map(Color).into_lua(lua)
|
||||
}
|
||||
mlua::Value::Nil | mlua::Value::Boolean(_) => {
|
||||
me.fg.map($crate::Color).into_lua(lua)
|
||||
me.fg.map(Color).into_lua(lua)
|
||||
}
|
||||
_ => {
|
||||
me.fg = Some($crate::Color::from_lua(value, lua)?.0);
|
||||
me.fg = Some(Color::from_lua(value, lua)?.0);
|
||||
ud.into_lua(lua)
|
||||
}
|
||||
}
|
||||
});
|
||||
$methods.add_function_mut("bg", |lua, (ud, value): (mlua::AnyUserData, mlua::Value)| {
|
||||
use $crate::elements::Color;
|
||||
use mlua::FromLua;
|
||||
use ratatui::style::Modifier;
|
||||
|
||||
let me = &mut ud.borrow_mut::<Self>()?.$($field).+;
|
||||
match value {
|
||||
mlua::Value::Boolean(true) if me.add_modifier.contains(Modifier::REVERSED) && !me.sub_modifier.contains(Modifier::REVERSED) => {
|
||||
me.fg.map($crate::Color).into_lua(lua)
|
||||
mlua::Value::Boolean(true) if me.has_modifier(Modifier::REVERSED) => {
|
||||
me.fg.map(Color).into_lua(lua)
|
||||
}
|
||||
mlua::Value::Nil | mlua::Value::Boolean(_) => {
|
||||
me.bg.map($crate::Color).into_lua(lua)
|
||||
me.bg.map(Color).into_lua(lua)
|
||||
}
|
||||
_ => {
|
||||
me.bg = Some($crate::Color::from_lua(value, lua)?.0);
|
||||
me.bg = Some(Color::from_lua(value, lua)?.0);
|
||||
ud.into_lua(lua)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use std::{any::TypeId, ffi::OsStr, io, process::Stdio};
|
||||
|
||||
use mlua::{AnyUserData, ExternalError, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
|
||||
use mlua::{AnyUserData, ExternalError, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
|
||||
use crate::Error;
|
||||
use yazi_shared::wtf8::FromWtf8;
|
||||
|
||||
use super::{Child, output::Output};
|
||||
use crate::process::Status;
|
||||
use crate::{Error, process::Status};
|
||||
|
||||
pub struct Command {
|
||||
inner: tokio::process::Command,
|
||||
|
|
@ -108,7 +107,7 @@ impl Command {
|
|||
}
|
||||
|
||||
impl UserData for Command {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
#[inline]
|
||||
fn make_stdio(v: Value) -> mlua::Result<Stdio> {
|
||||
match v {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,27 @@
|
|||
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::SER_OPT;
|
||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||
use ratatui::style::Modifier;
|
||||
|
||||
use crate::{SER_OPT, elements::Color};
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Style(pub ratatui::style::Style);
|
||||
|
||||
impl Deref for Style {
|
||||
type Target = ratatui::style::Style;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
||||
impl From<yazi_config::Style> for Style {
|
||||
fn from(value: yazi_config::Style) -> Self { Self(value.into()) }
|
||||
}
|
||||
|
||||
impl From<Style> for ratatui::style::Style {
|
||||
fn from(value: Style) -> ratatui::style::Style { value.0 }
|
||||
}
|
||||
|
||||
impl Style {
|
||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||
let new = lua.create_function(|_, (_, style): (Table, Self)| Ok(style))?;
|
||||
|
|
@ -16,10 +33,6 @@ impl Style {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<yazi_config::Style> for Style {
|
||||
fn from(value: yazi_config::Style) -> Self { Self(value.into()) }
|
||||
}
|
||||
|
||||
impl FromLua for Style {
|
||||
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
|
||||
Ok(Self(match value {
|
||||
|
|
@ -32,15 +45,93 @@ impl FromLua for Style {
|
|||
|
||||
impl UserData for Style {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
crate::impl_style_shorthands!(methods, 0);
|
||||
methods.add_method("fg", |lua, me, value: Value| match value {
|
||||
Value::Boolean(true) if me.has_modifier(Modifier::REVERSED) => me.bg.map(Color).into_lua(lua),
|
||||
Value::Nil | Value::Boolean(_) => me.fg.map(Color).into_lua(lua),
|
||||
_ => Self(me.fg(Color::from_lua(value, lua)?.0)).into_lua(lua),
|
||||
});
|
||||
|
||||
methods.add_method("bg", |lua, me, value: Value| match value {
|
||||
Value::Boolean(true) if me.has_modifier(Modifier::REVERSED) => me.fg.map(Color).into_lua(lua),
|
||||
Value::Nil | Value::Boolean(_) => me.bg.map(Color).into_lua(lua),
|
||||
_ => Self(me.bg(Color::from_lua(value, lua)?.0)).into_lua(lua),
|
||||
});
|
||||
|
||||
methods.add_method("bold", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
me.add_modifier(Modifier::BOLD)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("dim", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::DIM)
|
||||
} else {
|
||||
me.add_modifier(Modifier::DIM)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("italic", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::ITALIC)
|
||||
} else {
|
||||
me.add_modifier(Modifier::ITALIC)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("underline", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::UNDERLINED)
|
||||
} else {
|
||||
me.add_modifier(Modifier::UNDERLINED)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("blink", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::SLOW_BLINK)
|
||||
} else {
|
||||
me.add_modifier(Modifier::SLOW_BLINK)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("blink_rapid", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::RAPID_BLINK)
|
||||
} else {
|
||||
me.add_modifier(Modifier::RAPID_BLINK)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("reverse", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::REVERSED)
|
||||
} else {
|
||||
me.add_modifier(Modifier::REVERSED)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("hidden", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::HIDDEN)
|
||||
} else {
|
||||
me.add_modifier(Modifier::HIDDEN)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("crossed", |_, me, remove: bool| {
|
||||
Ok(Self(if remove {
|
||||
me.remove_modifier(Modifier::CROSSED_OUT)
|
||||
} else {
|
||||
me.add_modifier(Modifier::CROSSED_OUT)
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("patch", |_, me, other: Self| Ok(Self(me.patch(other))));
|
||||
|
||||
methods
|
||||
.add_method("raw", |lua, me, ()| lua.to_value_with(&yazi_config::Style::from(me.0), SER_OPT));
|
||||
|
||||
methods.add_function_mut("patch", |_, (ud, style): (AnyUserData, Self)| {
|
||||
let mut me = ud.borrow_mut::<Self>()?;
|
||||
me.0 = me.0.patch(style.0);
|
||||
Ok(ud)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ function Entity:redraw()
|
|||
return ui.Line(lines):style(self:style())
|
||||
end
|
||||
|
||||
---@return ui.Style
|
||||
function Entity:style()
|
||||
local s = self._file:style() or ui.Style()
|
||||
if not self._file.is_hovered then
|
||||
|
|
@ -109,6 +110,7 @@ function Entity:style()
|
|||
end
|
||||
end
|
||||
|
||||
---@return ui.Style?
|
||||
function Entity:style_rev()
|
||||
local s = self:style()
|
||||
local bg = s:bg(true)
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ function Status:new(area, tab)
|
|||
end
|
||||
|
||||
function Status:style()
|
||||
local m = th.mode
|
||||
local m, s = th.mode, ui.Style():fg("reset"):bg("reset")
|
||||
if self._tab.mode.is_select then
|
||||
return { main = m.select_main, alt = m.select_alt }
|
||||
return { main = s:patch(m.select_main), alt = s:patch(m.select_alt) }
|
||||
elseif self._tab.mode.is_unset then
|
||||
return { main = m.unset_main, alt = m.unset_alt }
|
||||
return { main = s:patch(m.unset_main), alt = s:patch(m.unset_alt) }
|
||||
else
|
||||
return { main = m.normal_main, alt = m.normal_alt }
|
||||
return { main = s:patch(m.normal_main), alt = s:patch(m.normal_alt) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ function Tabs:redraw()
|
|||
return {}
|
||||
end
|
||||
|
||||
local style = self:style()
|
||||
local lines = {
|
||||
ui.Line(th.tabs.sep_outer.open):fg(th.tabs.inactive:bg()),
|
||||
ui.Line(th.tabs.sep_outer.open):fg(style.inactive:bg()),
|
||||
}
|
||||
|
||||
local pos = lines[1]:width()
|
||||
|
|
@ -26,22 +27,30 @@ function Tabs:redraw()
|
|||
local name = ui.truncate(string.format(" %d %s ", i, cx.tabs[i].name), { max = max })
|
||||
if i == cx.tabs.idx then
|
||||
lines[#lines + 1] = ui.Line {
|
||||
ui.Span(th.tabs.sep_inner.open):fg(th.tabs.active:bg()):bg(th.tabs.inactive:bg()),
|
||||
ui.Span(name):style(th.tabs.active),
|
||||
ui.Span(th.tabs.sep_inner.close):fg(th.tabs.active:bg()):bg(th.tabs.inactive:bg()),
|
||||
ui.Span(th.tabs.sep_inner.open):fg(style.active:bg()):bg(style.inactive:bg()),
|
||||
ui.Span(name):style(style.active),
|
||||
ui.Span(th.tabs.sep_inner.close):fg(style.active:bg()):bg(style.inactive:bg()),
|
||||
}
|
||||
else
|
||||
lines[#lines + 1] = ui.Line(name):style(th.tabs.inactive)
|
||||
lines[#lines + 1] = ui.Line(name):style(style.inactive)
|
||||
end
|
||||
self._offsets[i], pos = pos, pos + lines[#lines]:width()
|
||||
end
|
||||
|
||||
lines[#lines + 1] = ui.Line(th.tabs.sep_outer.close):fg(th.tabs.inactive:bg())
|
||||
lines[#lines + 1] = ui.Line(th.tabs.sep_outer.close):fg(style.inactive:bg())
|
||||
return ui.Line(lines):area(self._area)
|
||||
end
|
||||
|
||||
function Tabs.height() return #cx.tabs > 1 and 1 or 0 end
|
||||
|
||||
function Tabs:style()
|
||||
local s = ui.Style():fg("reset"):bg("reset")
|
||||
return {
|
||||
active = s:patch(th.tabs.active),
|
||||
inactive = s:patch(th.tabs.inactive),
|
||||
}
|
||||
end
|
||||
|
||||
function Tabs:inner_width()
|
||||
local si, so = th.tabs.sep_inner, th.tabs.sep_outer
|
||||
return math.max(0, self._area.w - ui.Line({ si.open, si.close, so.open, so.close }):width())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl TaskIn for FetchIn {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,24 +50,24 @@ impl TaskIn for FileIn {
|
|||
}
|
||||
}
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
match self {
|
||||
Self::Copy(r#in) => _ = r#in.with_id(id),
|
||||
Self::CopyDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Cut(r#in) => _ = r#in.with_id(id),
|
||||
Self::CutDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Link(r#in) => _ = r#in.with_id(id),
|
||||
Self::LinkDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Hardlink(r#in) => _ = r#in.with_id(id),
|
||||
Self::HardlinkDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Delete(r#in) => _ = r#in.with_id(id),
|
||||
Self::DeleteDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Trash(r#in) => _ = r#in.with_id(id),
|
||||
Self::TrashDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Download(r#in) => _ = r#in.with_id(id),
|
||||
Self::DownloadDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Upload(r#in) => _ = r#in.with_id(id),
|
||||
Self::UploadDo(r#in) => _ = r#in.with_id(id),
|
||||
Self::Copy(r#in) => _ = r#in.set_id(id),
|
||||
Self::CopyDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Cut(r#in) => _ = r#in.set_id(id),
|
||||
Self::CutDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Link(r#in) => _ = r#in.set_id(id),
|
||||
Self::LinkDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Hardlink(r#in) => _ = r#in.set_id(id),
|
||||
Self::HardlinkDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Delete(r#in) => _ = r#in.set_id(id),
|
||||
Self::DeleteDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Trash(r#in) => _ = r#in.set_id(id),
|
||||
Self::TrashDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Download(r#in) => _ = r#in.set_id(id),
|
||||
Self::DownloadDo(r#in) => _ = r#in.set_id(id),
|
||||
Self::Upload(r#in) => _ = r#in.set_id(id),
|
||||
Self::UploadDo(r#in) => _ = r#in.set_id(id),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ impl TaskIn for FileInCopy {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ impl TaskIn for FileInCut {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ impl TaskIn for FileInLink {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ impl TaskIn for FileInHardlink {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -289,7 +289,7 @@ impl TaskIn for FileInDelete {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -309,7 +309,7 @@ impl TaskIn for FileInTrash {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ impl TaskIn for FileInDownload {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -353,7 +353,7 @@ impl TaskIn for FileInUpload {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl TaskIn for HookIn {
|
|||
}
|
||||
}
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
match self {
|
||||
Self::Copy(r#in) => r#in.id = id,
|
||||
Self::Cut(r#in) => r#in.id = id,
|
||||
|
|
@ -89,7 +89,7 @@ impl TaskIn for HookInOutCopy {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ impl TaskIn for HookInOutCut {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ impl TaskIn for HookInDelete {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -193,7 +193,7 @@ impl TaskIn for HookInTrash {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ impl TaskIn for HookInOutLink {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ impl TaskIn for HookInOutHardlink {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ impl TaskIn for HookInDownload {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -329,7 +329,7 @@ impl TaskIn for HookInUpload {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -359,7 +359,7 @@ impl TaskIn for HookInPreload {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub(crate) trait TaskIn {
|
|||
|
||||
fn id(&self) -> Id;
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self;
|
||||
fn set_id(&mut self, id: Id) -> &mut Self;
|
||||
|
||||
fn title(&self) -> Cow<'_, str>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl Ongoing {
|
|||
static IDS: Ids = Ids::new();
|
||||
let id = IDS.next();
|
||||
|
||||
let title = r#in.with_id(id).title().into_owned();
|
||||
let title = r#in.set_id(id).title().into_owned();
|
||||
let prog = T::Prog::default().into();
|
||||
|
||||
self.inner.entry(id).insert(Task::new(id, title, prog)).into_mut()
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ impl TaskIn for PluginIn {
|
|||
}
|
||||
}
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
match self {
|
||||
Self::Entry(r#in) => _ = r#in.with_id(id),
|
||||
Self::Entry(r#in) => _ = r#in.set_id(id),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ impl TaskIn for PluginInEntry {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ impl TaskIn for PreloadIn {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ impl TaskIn for ProcessIn {
|
|||
}
|
||||
}
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
match self {
|
||||
Self::Block(r#in) => _ = r#in.with_id(id),
|
||||
Self::Orphan(r#in) => _ = r#in.with_id(id),
|
||||
Self::Bg(r#in) => _ = r#in.with_id(id),
|
||||
Self::Block(r#in) => _ = r#in.set_id(id),
|
||||
Self::Orphan(r#in) => _ = r#in.set_id(id),
|
||||
Self::Bg(r#in) => _ = r#in.set_id(id),
|
||||
};
|
||||
self
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ impl TaskIn for ProcessInBlock {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ impl TaskIn for ProcessInOrphan {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ impl TaskIn for ProcessInBg {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ impl TaskIn for SizeIn {
|
|||
|
||||
fn id(&self) -> Id { self.id }
|
||||
|
||||
fn with_id(&mut self, id: Id) -> &mut Self {
|
||||
fn set_id(&mut self, id: Id) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl Task {
|
|||
|
||||
pub(super) fn with_hook(&mut self, hook: impl Into<HookIn>) -> &mut Self {
|
||||
let mut hook = hook.into();
|
||||
hook.with_id(self.id);
|
||||
hook.set_id(self.id);
|
||||
|
||||
self.hook = Some(hook);
|
||||
self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue