Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions yazi-plugin/preset/components/current.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Current:empty()
end

return {
ui.Line(s):area(self._area):align(ui.Line.CENTER),
ui.Line(s):area(self._area):align(ui.Align.CENTER),
}
end

Expand All @@ -43,7 +43,7 @@ function Current:redraw()

return {
ui.List(left):area(self._area),
ui.Text(right):area(self._area):align(ui.Text.RIGHT),
ui.Text(right):area(self._area):align(ui.Align.RIGHT),
}
end

Expand Down
3 changes: 2 additions & 1 deletion yazi-plugin/preset/components/header.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Header = {
-- TODO: remove these two constants
LEFT = 0,
RIGHT = 1,

Expand Down Expand Up @@ -83,7 +84,7 @@ function Header:redraw()

return {
ui.Line(left):area(self._area),
ui.Line(right):area(self._area):align(ui.Line.RIGHT),
ui.Line(right):area(self._area):align(ui.Align.RIGHT),
}
end

Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/components/marker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Marker:redraw()
w = 1,
h = math.min(1 + last[2] - last[1], self._area.y + self._area.h - y),
}
elements[#elements + 1] = ui.Bar(ui.Bar.LEFT):area(rect):style(last[3])
elements[#elements + 1] = ui.Bar(ui.Edge.LEFT):area(rect):style(last[3])
end

local last = { 0, 0, nil } -- start, end, style
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/preset/components/rail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ end

function Rail:build()
self._base = {
ui.Bar(ui.Bar.RIGHT):area(self._chunks[1]):symbol(th.mgr.border_symbol):style(th.mgr.border_style),
ui.Bar(ui.Bar.LEFT):area(self._chunks[3]):symbol(th.mgr.border_symbol):style(th.mgr.border_style),
ui.Bar(ui.Edge.RIGHT):area(self._chunks[1]):symbol(th.mgr.border_symbol):style(th.mgr.border_style),
ui.Bar(ui.Edge.LEFT):area(self._chunks[3]):symbol(th.mgr.border_symbol):style(th.mgr.border_style),
}
self._children = {
Marker:new(self._chunks[1], self._tab.parent),
Expand Down
3 changes: 2 additions & 1 deletion yazi-plugin/preset/components/status.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Status = {
-- TODO: remove these two constants
LEFT = 0,
RIGHT = 1,

Expand Down Expand Up @@ -141,7 +142,7 @@ function Status:redraw()
return {
ui.Text(""):area(self._area):style(th.status.overall),
ui.Line(left):area(self._area),
ui.Line(right):area(self._area):align(ui.Line.RIGHT),
ui.Line(right):area(self._area):align(ui.Align.RIGHT),
table.unpack(ui.redraw(Progress:new(self._area, right_width))),
}
end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/archive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function M:peek(job)
else
ya.preview_widget(job, {
ui.Text(left):area(job.area),
ui.Text(right):area(job.area):align(ui.Text.RIGHT),
ui.Text(right):area(job.area):align(ui.Align.RIGHT),
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/empty.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local M = {}

function M.msg(job, s) ya.preview_widget(job, ui.Text(ui.Line(s):reverse()):area(job.area):wrap(ui.Text.WRAP)) end
function M.msg(job, s) ya.preview_widget(job, ui.Text(ui.Line(s):reverse()):area(job.area):wrap(ui.Wrap.YES)) end

function M:peek(job)
local path = tostring(job.file.url)
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function M:peek(job)
text = ui.Text(string.format("Failed to start `%s`, error: %s", cmd, err))
end

ya.preview_widget(job, text:area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, text:area(job.area):wrap(ui.Wrap.YES))
end

function M:seek() end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function M:peek(job)
if #folder.files == 0 then
local done, err = folder.stage()
local s = not done and "Loading..." or not err and "No items" or string.format("Error: %s", err)
return ya.preview_widget(job, ui.Line(s):area(job.area):align(ui.Line.CENTER))
return ya.preview_widget(job, ui.Line(s):area(job.area):align(ui.Align.CENTER))
end

local items = {}
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/font.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek() end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(url, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek() end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function M:peek(job)
lines = lines:gsub("\t", string.rep(" ", rt.preview.tab_size))
ya.preview_widget(
job,
ui.Text.parse(lines):area(job.area):wrap(rt.preview.wrap == "yes" and ui.Text.WRAP or ui.Text.WRAP_NO)
ui.Text.parse(lines):area(job.area):wrap(rt.preview.wrap == "yes" and ui.Wrap.YES or ui.Wrap.NO)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/magick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek() end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/pdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek(job)
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/svg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek() end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/video.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function M:peek(job)
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))

local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Text.WRAP))
ya.preview_widget(job, err and ui.Text(tostring(err)):area(job.area):wrap(ui.Wrap.YES))
end

function M:seek(job)
Expand Down
42 changes: 42 additions & 0 deletions yazi-plugin/src/elements/align.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::ops::Deref;

use mlua::{FromLua, IntoLua, Lua, Value};

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Align(pub(super) ratatui::layout::Alignment);

impl Deref for Align {
type Target = ratatui::layout::Alignment;

fn deref(&self) -> &Self::Target { &self.0 }
}

impl Align {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
lua.create_table_from([("LEFT", 0), ("CENTER", 1), ("RIGHT", 2)])?.into_lua(lua)
}
}

impl FromLua for Align {
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
let Value::Integer(n) = value else {
return Err(mlua::Error::FromLuaConversionError {
from: value.type_name(),
to: "Align".to_string(),
message: Some("expected an integer representation of Align".to_string()),
});
};
Ok(Self(match n {
0 => ratatui::layout::Alignment::Left,
1 => ratatui::layout::Alignment::Center,
2 => ratatui::layout::Alignment::Right,
_ => {
return Err(mlua::Error::FromLuaConversionError {
from: value.type_name(),
to: "Align".to_string(),
message: Some("invalid value for Align".to_string()),
});
}
}))
}
}
31 changes: 15 additions & 16 deletions yazi-plugin/src/elements/bar.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, Value};
use ratatui::widgets::Borders;

use super::Area;
use super::{Area, Edge};

#[derive(Clone, Debug, Default)]
pub struct Bar {
area: Area,

direction: ratatui::widgets::Borders,
symbol: String,
style: ratatui::style::Style,
edge: Edge,
symbol: String,
style: ratatui::style::Style,
}

impl Bar {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, direction): (Table, u8)| {
Ok(Self { direction: Borders::from_bits_truncate(direction), ..Default::default() })
})?;
let new =
lua.create_function(|_, (_, edge): (Table, Edge)| Ok(Self { edge, ..Default::default() }))?;

let bar = lua.create_table_from([
// Direction
// TODO: remove these constants
("NONE", Borders::NONE.bits()),
("TOP", Borders::TOP.bits()),
("RIGHT", Borders::RIGHT.bits()),
Expand All @@ -44,31 +43,31 @@ impl Bar {

let symbol = if !self.symbol.is_empty() {
&self.symbol
} else if self.direction.intersects(Borders::TOP | Borders::BOTTOM) {
} else if self.edge.intersects(Borders::TOP | Borders::BOTTOM) {
"─"
} else if self.direction.intersects(Borders::LEFT | Borders::RIGHT) {
} else if self.edge.intersects(Borders::LEFT | Borders::RIGHT) {
"│"
} else {
" "
};

if self.direction.contains(Borders::LEFT) {
if self.edge.contains(Borders::LEFT) {
for y in rect.top()..rect.bottom() {
buf[(rect.left(), y)].set_style(self.style).set_symbol(symbol);
}
}
if self.direction.contains(Borders::TOP) {
if self.edge.contains(Borders::TOP) {
for x in rect.left()..rect.right() {
buf[(x, rect.top())].set_style(self.style).set_symbol(symbol);
}
}
if self.direction.contains(Borders::RIGHT) {
if self.edge.contains(Borders::RIGHT) {
let x = rect.right() - 1;
for y in rect.top()..rect.bottom() {
buf[(x, y)].set_style(self.style).set_symbol(symbol);
}
}
if self.direction.contains(Borders::BOTTOM) {
if self.edge.contains(Borders::BOTTOM) {
let y = rect.bottom() - 1;
for x in rect.left()..rect.right() {
buf[(x, y)].set_style(self.style).set_symbol(symbol);
Expand All @@ -82,8 +81,8 @@ impl UserData for Bar {
crate::impl_area_method!(methods);
crate::impl_style_method!(methods, style);

methods.add_function_mut("direction", |_, (ud, symbol): (AnyUserData, u8)| {
ud.borrow_mut::<Self>()?.direction = Borders::from_bits_truncate(symbol);
methods.add_function_mut("edge", |_, (ud, edge): (AnyUserData, Edge)| {
ud.borrow_mut::<Self>()?.edge = edge;
Ok(ud)
});
methods.add_function_mut("symbol", |_, (ud, symbol): (AnyUserData, String)| {
Expand Down
24 changes: 10 additions & 14 deletions yazi-plugin/src/elements/border.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, UserData, Value};
use ratatui::widgets::{Borders, Widget};

use super::Area;
use super::{Area, Edge};
use crate::elements::Line;

// Type
Expand All @@ -16,24 +16,20 @@ const QUADRANT_OUTSIDE: u8 = 5;
pub struct Border {
pub(crate) area: Area,

pub(crate) position: ratatui::widgets::Borders,
pub(crate) r#type: ratatui::widgets::BorderType,
pub(crate) style: ratatui::style::Style,
pub(crate) edge: Edge,
pub(crate) r#type: ratatui::widgets::BorderType,
pub(crate) style: ratatui::style::Style,

pub(crate) titles: Vec<(ratatui::widgets::block::Position, ratatui::text::Line<'static>)>,
}

impl Border {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, position): (Table, u8)| {
Ok(Border {
position: ratatui::widgets::Borders::from_bits_truncate(position),
..Default::default()
})
})?;
let new = lua
.create_function(|_, (_, edge): (Table, Edge)| Ok(Border { edge, ..Default::default() }))?;

let border = lua.create_table_from([
// Position
// TODO: remove these constants
("NONE", Borders::NONE.bits()),
("TOP", Borders::TOP.bits()),
("RIGHT", Borders::RIGHT.bits()),
Expand All @@ -59,7 +55,7 @@ impl Border {
trans: impl FnOnce(yazi_config::popup::Position) -> ratatui::layout::Rect,
) {
let mut block = ratatui::widgets::Block::default()
.borders(self.position)
.borders(self.edge.0)
.border_type(self.r#type)
.border_style(self.style);

Expand Down Expand Up @@ -103,8 +99,8 @@ impl UserData for Border {
Ok(ud)
},
);
methods.add_function_mut("position", |_, (ud, position): (AnyUserData, u8)| {
ud.borrow_mut::<Self>()?.position = ratatui::widgets::Borders::from_bits_truncate(position);
methods.add_function_mut("edge", |_, (ud, edge): (AnyUserData, Edge)| {
ud.borrow_mut::<Self>()?.edge = edge;
Ok(ud)
});
}
Expand Down
Loading
Loading