Repository: sxyazi/yazi
File: yazi-binding/src/elements/border.rs (Rust)

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

// Type
const PLAIN: u8 = 0;
const ROUNDED: u8 = 1;
const DOUBLE: u8 = 2;
const THICK: u8 = 3;
const QUADRANT_INSIDE: u8 = 4;
const QUADRANT_OUTSIDE: u8 = 5;

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

	pub edge:   Edge,
	pub r#type: ratatui::widgets::BorderType,
	pub style:  ratatui::style::Style,

	pub 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(|_, (_, edge): (Table, Edge)| Ok(Border { edge, ..Default::default() }))?;

		let border = lua.create_table_from([
			// Type
			("PLAIN", PLAIN),
			("ROUNDED", ROUNDED),
			("DOUBLE", DOUBLE),
			("THICK", THICK),
			("QUADRANT_INSIDE", QUADRANT_INSIDE),
			("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
		])?;

		border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
		border.into_lua(lua)
	}

	pub(super) fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
		let mut block = ratatui::widgets::Block::default()
			.borders(self.edge.0)
			.border_type(self.r#type)
			.border_style(self.style);

		for title in self.titles {
			block = match title {
				(ratatui::widgets::block::Position::Top, line) => block.title(line),
				(ratatui::widgets::block::Position::Bottom, line) => block.title(line),

Review comment (suggestion):
The hardcoded `BorderType::Rounded` overrides the default behavior. This should either use `Default::default()` for the entire struct or make the border type configurable through the function parameters.
```suggestion
		let new = lua.create_function(|_, (_, edge, border_type): (Table, Edge, u8)| {
			let r#type = match border_type {
				ROUNDED => ratatui::widgets::BorderType::Rounded,
				DOUBLE => ratatui::widgets::BorderType::Double,
				THICK => ratatui::widgets::BorderType::Thick,
				QUADRANT_INSIDE => ratatui::widgets::BorderType::QuadrantInside,
				QUADRANT_OUTSIDE => ratatui::widgets::BorderType::QuadrantOutside,
				_ => ratatui::widgets::BorderType::Plain,
			};
			Ok(Border { edge, r#type, ..Default::default() })
```

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

// Type
const PLAIN: u8 = 0;
const ROUNDED: u8 = 1;
const DOUBLE: u8 = 2;
const THICK: u8 = 3;
const QUADRANT_INSIDE: u8 = 4;
const QUADRANT_OUTSIDE: u8 = 5;

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

	pub edge:   Edge,
	pub r#type: ratatui::widgets::BorderType,
	pub style:  ratatui::style::Style,

	pub 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(|_, (_, edge): (Table, Edge)| {
			Ok(Border { edge, r#type: ratatui::widgets::BorderType::Rounded, ..Default::default() })
		})?;

		let border = lua.create_table_from([
			// Type
			("PLAIN", PLAIN),
			("ROUNDED", ROUNDED),
			("DOUBLE", DOUBLE),
			("THICK", THICK),
			("QUADRANT_INSIDE", QUADRANT_INSIDE),
			("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
		])?;

		border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
		border.into_lua(lua)
	}

	pub(super) fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
		let mut block = ratatui::widgets::Block::default()
			.borders(self.edge.0)
			.border_type(self.r#type)
			.border_style(self.style);

		for title in self.titles {
			block = match title {
				(ratatui::widgets::block::Position::Top, line) => block.title(line),