mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: ensure that Entity and Linemode have consistent space padding (#1580)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
907ac09e34
commit
fdd574997b
4 changed files with 27 additions and 18 deletions
|
|
@ -1,24 +1,27 @@
|
||||||
Entity = {
|
Entity = {
|
||||||
_inc = 1000,
|
_inc = 1000,
|
||||||
_children = {
|
_children = {
|
||||||
{ "icon", id = 1, order = 1000 },
|
{ "space", id = 1, order = 1000 },
|
||||||
{ "prefix", id = 2, order = 2000 },
|
{ "icon", id = 2, order = 2000 },
|
||||||
{ "highlights", id = 3, order = 3000 },
|
{ "prefix", id = 3, order = 3000 },
|
||||||
{ "found", id = 4, order = 4000 },
|
{ "highlights", id = 4, order = 4000 },
|
||||||
{ "symlink", id = 5, order = 5000 },
|
{ "found", id = 5, order = 5000 },
|
||||||
|
{ "symlink", id = 6, order = 6000 },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
||||||
|
|
||||||
|
function Entity:space() return ui.Line(" ") end
|
||||||
|
|
||||||
function Entity:icon()
|
function Entity:icon()
|
||||||
local icon = self._file:icon()
|
local icon = self._file:icon()
|
||||||
if not icon then
|
if not icon then
|
||||||
return ui.Line("")
|
return ui.Line("")
|
||||||
elseif self._file:is_hovered() then
|
elseif self._file:is_hovered() then
|
||||||
return ui.Line(" " .. icon.text .. " ")
|
return ui.Line(icon.text .. " ")
|
||||||
else
|
else
|
||||||
return ui.Line(" " .. icon.text .. " "):style(icon.style)
|
return ui.Line(icon.text .. " "):style(icon.style)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,24 @@ Linemode = {
|
||||||
_inc = 1000,
|
_inc = 1000,
|
||||||
_children = {
|
_children = {
|
||||||
{ "solo", id = 1, order = 1000 },
|
{ "solo", id = 1, order = 1000 },
|
||||||
|
{ "space", id = 2, order = 2000 },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
||||||
|
|
||||||
|
function Linemode:space() return ui.Line(" ") end
|
||||||
|
|
||||||
function Linemode:solo()
|
function Linemode:solo()
|
||||||
local mode = cx.active.conf.linemode
|
local mode = cx.active.conf.linemode
|
||||||
if mode == "none" or mode == "solo" then
|
if mode == "none" or mode == "solo" then
|
||||||
return ui.Line("")
|
return ui.Line("")
|
||||||
|
elseif not self[mode] then
|
||||||
|
return ui.Line(" " .. mode)
|
||||||
|
else
|
||||||
|
local line = self[mode](self)
|
||||||
|
return line:visible() and ui.Line { ui.Span(" "), line } or line
|
||||||
end
|
end
|
||||||
|
|
||||||
if not self[mode] then
|
|
||||||
return ui.Line(" " .. mode .. " ")
|
|
||||||
end
|
|
||||||
|
|
||||||
return ui.Line {
|
|
||||||
ui.Span(" "),
|
|
||||||
self[mode](self),
|
|
||||||
ui.Span(" "),
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Linemode:size()
|
function Linemode:size()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::mem;
|
||||||
|
|
||||||
use ansi_to_tui::IntoText;
|
use ansi_to_tui::IntoText;
|
||||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, UserDataMethods, Value};
|
||||||
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
use super::{Span, Style};
|
use super::{Span, Style};
|
||||||
|
|
||||||
|
|
@ -84,7 +85,7 @@ impl UserData for Line {
|
||||||
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
crate::impl_style_shorthands!(methods, 0.style);
|
crate::impl_style_shorthands!(methods, 0.style);
|
||||||
|
|
||||||
methods.add_function("width", |_, ud: AnyUserData| Ok(ud.borrow_mut::<Self>()?.0.width()));
|
methods.add_method("width", |_, me, ()| Ok(me.0.width()));
|
||||||
methods.add_function("style", |_, (ud, value): (AnyUserData, Value)| {
|
methods.add_function("style", |_, (ud, value): (AnyUserData, Value)| {
|
||||||
{
|
{
|
||||||
let mut me = ud.borrow_mut::<Self>()?;
|
let mut me = ud.borrow_mut::<Self>()?;
|
||||||
|
|
@ -105,5 +106,8 @@ impl UserData for Line {
|
||||||
});
|
});
|
||||||
Ok(ud)
|
Ok(ud)
|
||||||
});
|
});
|
||||||
|
methods.add_method("visible", |_, me, ()| {
|
||||||
|
Ok(me.0.iter().flat_map(|s| s.content.chars()).any(|c| c.width().unwrap_or(0) > 0))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use mlua::{AnyUserData, ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{AnyUserData, ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value};
|
||||||
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
use super::Style;
|
use super::Style;
|
||||||
|
|
||||||
|
|
@ -29,5 +30,8 @@ impl UserData for Span {
|
||||||
};
|
};
|
||||||
Ok(ud)
|
Ok(ud)
|
||||||
});
|
});
|
||||||
|
methods.add_method("visible", |_, me, ()| {
|
||||||
|
Ok(me.0.content.chars().any(|c| c.width().unwrap_or(0) > 0))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue