-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
Manager
component for better style extensions
- Loading branch information
Showing
24 changed files
with
313 additions
and
184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ mod executor; | |
mod help; | ||
mod input; | ||
mod logs; | ||
mod manager; | ||
mod root; | ||
mod select; | ||
mod signals; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Manager = {} | ||
|
||
function Manager:render(area) | ||
local chunks = ui.Layout() | ||
:direction(ui.Direction.HORIZONTAL) | ||
:constraints({ | ||
ui.Constraint.Ratio(MANAGER.layout.parent, MANAGER.layout.all), | ||
ui.Constraint.Ratio(MANAGER.layout.current, MANAGER.layout.all), | ||
ui.Constraint.Ratio(MANAGER.layout.preview, MANAGER.layout.all), | ||
}) | ||
:split(area) | ||
|
||
return { | ||
-- Parent | ||
table.unpack(Folder:render(chunks[1]:padding(ui.Padding.x(1)), { kind = Folder.Kind.Parent })), | ||
-- Current | ||
table.unpack(Folder:render(chunks[2], { kind = Folder.Kind.Current })), | ||
-- Preview | ||
ui.Base(chunks[3]:padding(ui.Padding.x(1)), "Preview"), | ||
|
||
-- Borders | ||
ui.Bar(chunks[1], ui.Position.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style), | ||
ui.Bar(chunks[3], ui.Position.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style), | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use mlua::{FromLua, Lua, Table, UserData, Value}; | ||
use ratatui::widgets::Widget; | ||
|
||
use crate::{layout::Rect, GLOBALS, LUA}; | ||
|
||
#[derive(Clone)] | ||
pub struct Base { | ||
area: ratatui::layout::Rect, | ||
|
||
name: String, | ||
} | ||
|
||
impl Base { | ||
pub(crate) fn install() -> mlua::Result<()> { | ||
let ui: Table = GLOBALS.get("ui")?; | ||
ui.set( | ||
"Base", | ||
LUA.create_function(|_, (area, name): (Rect, String)| Ok(Self { area: area.0, name }))?, | ||
) | ||
} | ||
|
||
pub fn render(self, cx: &core::Ctx, buf: &mut ratatui::buffer::Buffer) { | ||
match self.name.as_ref() { | ||
"Preview" => super::Preview::new(cx).render(self.area, buf), | ||
_ => {} | ||
} | ||
} | ||
} | ||
|
||
impl<'lua> FromLua<'lua> for Base { | ||
fn from_lua(value: Value<'lua>, _: &'lua Lua) -> mlua::Result<Self> { | ||
match value { | ||
Value::UserData(ud) => Ok(ud.borrow::<Self>()?.clone()), | ||
_ => Err(mlua::Error::FromLuaConversionError { | ||
from: value.type_name(), | ||
to: "Base", | ||
message: Some("expected a Base".to_string()), | ||
}), | ||
} | ||
} | ||
} | ||
|
||
impl UserData for Base {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use mlua::{AnyUserData, Table}; | ||
use shared::RoCell; | ||
|
||
use super::Base; | ||
use crate::{layout::{Bar, Gauge, List, Paragraph}, GLOBALS}; | ||
|
||
pub(super) static COMP_FOLDER: RoCell<Table> = RoCell::new(); | ||
pub(super) static COMP_HEADER: RoCell<Table> = RoCell::new(); | ||
pub(super) static COMP_MANAGER: RoCell<Table> = RoCell::new(); | ||
pub(super) static COMP_STATUS: RoCell<Table> = RoCell::new(); | ||
|
||
pub fn init() -> mlua::Result<()> { | ||
COMP_FOLDER.init(GLOBALS.get("Folder")?); | ||
COMP_HEADER.init(GLOBALS.get("Header")?); | ||
COMP_MANAGER.init(GLOBALS.get("Manager")?); | ||
COMP_STATUS.init(GLOBALS.get("Status")?); | ||
Ok(()) | ||
} | ||
|
||
pub(super) fn layout( | ||
values: Vec<AnyUserData>, | ||
cx: &core::Ctx, | ||
buf: &mut ratatui::prelude::Buffer, | ||
) -> mlua::Result<()> { | ||
for value in values { | ||
if let Ok(c) = value.take::<Paragraph>() { | ||
c.render(buf) | ||
} else if let Ok(c) = value.take::<List>() { | ||
c.render(buf) | ||
} else if let Ok(c) = value.take::<Bar>() { | ||
c.render(buf) | ||
} else if let Ok(c) = value.take::<Base>() { | ||
c.render(cx, buf) | ||
} else if let Ok(c) = value.take::<Gauge>() { | ||
c.render(buf) | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use mlua::TableExt; | ||
use ratatui::widgets::Widget; | ||
use tracing::error; | ||
|
||
use super::{layout, COMP_FOLDER}; | ||
use crate::{layout::Rect, LUA}; | ||
|
||
pub struct Folder<'a> { | ||
cx: &'a core::Ctx, | ||
kind: u8, | ||
} | ||
|
||
impl<'a> Folder<'a> { | ||
#[inline] | ||
pub fn parent(cx: &'a core::Ctx) -> Self { Self { cx, kind: 0 } } | ||
|
||
#[inline] | ||
pub fn current(cx: &'a core::Ctx) -> Self { Self { cx, kind: 1 } } | ||
|
||
#[inline] | ||
pub fn preview(cx: &'a core::Ctx) -> Self { Self { cx, kind: 2 } } | ||
} | ||
|
||
impl<'a> Widget for Folder<'a> { | ||
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) { | ||
let mut f = || { | ||
let args = LUA.create_table()?; | ||
args.set("kind", self.kind)?; | ||
layout(COMP_FOLDER.call_method::<_, _>("render", (Rect(area), args))?, self.cx, buf) | ||
}; | ||
if let Err(e) = f() { | ||
error!("{:?}", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use mlua::TableExt; | ||
use ratatui::widgets::Widget; | ||
use tracing::error; | ||
|
||
use super::{layout, COMP_HEADER}; | ||
use crate::layout::Rect; | ||
|
||
pub struct Header<'a> { | ||
cx: &'a core::Ctx, | ||
} | ||
|
||
impl<'a> Header<'a> { | ||
#[inline] | ||
pub fn new(cx: &'a core::Ctx) -> Self { Self { cx } } | ||
} | ||
|
||
impl<'a> Widget for Header<'a> { | ||
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) { | ||
let mut f = || layout(COMP_HEADER.call_method::<_, _>("render", Rect(area))?, self.cx, buf); | ||
if let Err(e) = f() { | ||
error!("{:?}", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.