|
|
@ -1,30 +1,225 @@
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
|
|
use helix_view::Editor;
|
|
|
|
use helix_core::Position;
|
|
|
|
|
|
|
|
use helix_view::{
|
|
|
|
|
|
|
|
graphics::{Color, CursorKind, Rect, UnderlineStyle},
|
|
|
|
|
|
|
|
input::{Event, KeyEvent},
|
|
|
|
|
|
|
|
keyboard::{KeyCode, KeyModifiers},
|
|
|
|
|
|
|
|
theme::Style,
|
|
|
|
|
|
|
|
Editor,
|
|
|
|
|
|
|
|
};
|
|
|
|
use steel::{
|
|
|
|
use steel::{
|
|
|
|
rvals::{Custom, FromSteelVal, IntoSteelVal},
|
|
|
|
rvals::{Custom, FromSteelVal, IntoSteelVal},
|
|
|
|
steel_vm::{builtin::BuiltInModule, engine::Engine, register_fn::RegisterFn},
|
|
|
|
steel_vm::{
|
|
|
|
|
|
|
|
builtin::BuiltInModule,
|
|
|
|
|
|
|
|
engine::Engine,
|
|
|
|
|
|
|
|
register_fn::{MarkerWrapper1, RegisterFn},
|
|
|
|
|
|
|
|
},
|
|
|
|
SteelVal,
|
|
|
|
SteelVal,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
use tui::{
|
|
|
|
|
|
|
|
buffer::Buffer,
|
|
|
|
|
|
|
|
widgets::{Block, BorderType, Borders, Widget},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
commands::{engine::steel::ENGINE, Context},
|
|
|
|
commands::{
|
|
|
|
|
|
|
|
engine::steel::{BoxDynComponent, ENGINE},
|
|
|
|
|
|
|
|
Context,
|
|
|
|
|
|
|
|
},
|
|
|
|
compositor::{self, Component},
|
|
|
|
compositor::{self, Component},
|
|
|
|
ui::{Popup, Prompt, PromptEvent},
|
|
|
|
ctrl, key,
|
|
|
|
|
|
|
|
ui::{overlay::overlaid, Popup, Prompt, PromptEvent},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use super::steel::WrappedDynComponent;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Move the main configuration function to use this instead
|
|
|
|
// TODO: Move the main configuration function to use this instead
|
|
|
|
pub fn helix_component_module() -> BuiltInModule {
|
|
|
|
pub fn helix_component_module() -> BuiltInModule {
|
|
|
|
let mut module = BuiltInModule::new("helix/components".to_string());
|
|
|
|
let mut module = BuiltInModule::new("helix/components".to_string());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module
|
|
|
|
|
|
|
|
.register_fn("frame-set-string!", buffer_set_string)
|
|
|
|
|
|
|
|
.register_fn("position", Position::new)
|
|
|
|
|
|
|
|
.register_fn("position-row", |position: &Position| position.row)
|
|
|
|
|
|
|
|
.register_fn("position-col", |position: &Position| position.col)
|
|
|
|
|
|
|
|
.register_fn("area", helix_view::graphics::Rect::new)
|
|
|
|
|
|
|
|
.register_fn("area-x", |area: &helix_view::graphics::Rect| area.x)
|
|
|
|
|
|
|
|
.register_fn("area-y", |area: &helix_view::graphics::Rect| area.y)
|
|
|
|
|
|
|
|
.register_fn("area-width", |area: &helix_view::graphics::Rect| area.width)
|
|
|
|
|
|
|
|
.register_fn("area-height", |area: &helix_view::graphics::Rect| {
|
|
|
|
|
|
|
|
area.height
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn("overlaid", |component: &mut WrappedDynComponent| {
|
|
|
|
|
|
|
|
let inner: Option<Box<dyn Component>> = component
|
|
|
|
|
|
|
|
.inner
|
|
|
|
|
|
|
|
.take()
|
|
|
|
|
|
|
|
.map(|x| Box::new(overlaid(BoxDynComponent::new(x))) as Box<dyn Component>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
component.inner = inner;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn("block", || {
|
|
|
|
|
|
|
|
Block::default()
|
|
|
|
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
|
|
|
.border_style(Style::default().fg(Color::White))
|
|
|
|
|
|
|
|
.border_type(BorderType::Rounded)
|
|
|
|
|
|
|
|
.style(Style::default().bg(Color::Black))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn(
|
|
|
|
|
|
|
|
"block/render",
|
|
|
|
|
|
|
|
|buf: &mut Buffer, area: Rect, block: Block| block.render(area, buf),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_fn("buffer/clear", Buffer::clear)
|
|
|
|
|
|
|
|
.register_fn("buffer/clear-with", Buffer::clear_with)
|
|
|
|
|
|
|
|
.register_value("Color/Reset", Color::Reset.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Black", Color::Black.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Red", Color::Red.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/White", Color::White.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Green", Color::Green.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Yellow", Color::Yellow.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Blue", Color::Blue.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Magenta", Color::Magenta.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Cyan", Color::Cyan.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/Gray", Color::Gray.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/LightRed", Color::LightRed.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Color/LightGreen",
|
|
|
|
|
|
|
|
Color::LightGreen.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Color/LightYellow",
|
|
|
|
|
|
|
|
Color::LightYellow.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value("Color/LightBlue", Color::LightBlue.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Color/LightMagenta",
|
|
|
|
|
|
|
|
Color::LightMagenta.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value("Color/LightCyan", Color::LightCyan.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_value("Color/LightGray", Color::LightGray.into_steelval().unwrap())
|
|
|
|
|
|
|
|
.register_fn("Color/rgb", Color::Rgb)
|
|
|
|
|
|
|
|
.register_fn("Color/Indexed", Color::Indexed)
|
|
|
|
|
|
|
|
.register_fn("style-fg", Style::fg)
|
|
|
|
|
|
|
|
.register_fn("style-bg", Style::bg)
|
|
|
|
|
|
|
|
.register_fn("style-underline-color", Style::underline_color)
|
|
|
|
|
|
|
|
.register_fn("style-underline-style", Style::underline_style)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/Reset",
|
|
|
|
|
|
|
|
UnderlineStyle::Reset.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/Line",
|
|
|
|
|
|
|
|
UnderlineStyle::Line.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/Curl",
|
|
|
|
|
|
|
|
UnderlineStyle::Curl.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/Dotted",
|
|
|
|
|
|
|
|
UnderlineStyle::Dotted.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/Dashed",
|
|
|
|
|
|
|
|
UnderlineStyle::Dashed.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"Underline/DoubleLine",
|
|
|
|
|
|
|
|
UnderlineStyle::DoubleLine.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_fn("style", || Style::default())
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"event-result/consume",
|
|
|
|
|
|
|
|
SteelEventResult::Consumed.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"event-result/ignore",
|
|
|
|
|
|
|
|
SteelEventResult::Ignored.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"event-result/close",
|
|
|
|
|
|
|
|
SteelEventResult::Close.into_steelval().unwrap(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: Use a reference here instead of passing by value.
|
|
|
|
|
|
|
|
.register_fn("key-event-char", |event: Event| {
|
|
|
|
|
|
|
|
if let Event::Key(event) = event {
|
|
|
|
|
|
|
|
event.char()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn("key-event-modifier", |event: Event| {
|
|
|
|
|
|
|
|
if let Event::Key(KeyEvent { modifiers, .. }) = event {
|
|
|
|
|
|
|
|
Some(modifiers.bits())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"key-modifier-ctrl",
|
|
|
|
|
|
|
|
SteelVal::IntV(KeyModifiers::CONTROL.bits() as isize),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"key-modifier-shift",
|
|
|
|
|
|
|
|
SteelVal::IntV(KeyModifiers::SHIFT.bits() as isize),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_value(
|
|
|
|
|
|
|
|
"key-modifier-alt",
|
|
|
|
|
|
|
|
SteelVal::IntV(KeyModifiers::ALT.bits() as isize),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.register_fn("key-event-escape?", |event: Event| {
|
|
|
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Esc, ..
|
|
|
|
|
|
|
|
}) = event
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn("key-event-backspace?", |event: Event| {
|
|
|
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Backspace,
|
|
|
|
|
|
|
|
..
|
|
|
|
|
|
|
|
}) = event
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.register_fn("key-event-enter?", |event: Event| {
|
|
|
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
|
|
|
|
..
|
|
|
|
|
|
|
|
}) = event
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module
|
|
|
|
module
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A dynamic component, used for rendering thing
|
|
|
|
fn buffer_set_string(
|
|
|
|
|
|
|
|
buffer: &mut tui::buffer::Buffer,
|
|
|
|
|
|
|
|
x: u16,
|
|
|
|
|
|
|
|
y: u16,
|
|
|
|
|
|
|
|
string: steel::rvals::SteelString,
|
|
|
|
|
|
|
|
style: Style,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
buffer.set_string(x, y, string.as_str(), style)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// A dynamic component, used for rendering
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
// TODO: Implement `trace` method for objects that hold steel vals
|
|
|
|
|
|
|
|
pub struct SteelDynamicComponent {
|
|
|
|
pub struct SteelDynamicComponent {
|
|
|
|
name: String,
|
|
|
|
// TODO: currently the component id requires using a &'static str,
|
|
|
|
|
|
|
|
// however in a world with dynamic components that might not be
|
|
|
|
|
|
|
|
// the case anymore
|
|
|
|
|
|
|
|
_name: String,
|
|
|
|
// This _should_ be a struct, but in theory can be whatever you want. It will be the first argument
|
|
|
|
// This _should_ be a struct, but in theory can be whatever you want. It will be the first argument
|
|
|
|
// passed to the functions in the remainder of the struct.
|
|
|
|
// passed to the functions in the remainder of the struct.
|
|
|
|
state: SteelVal,
|
|
|
|
state: SteelVal,
|
|
|
@ -33,6 +228,11 @@ pub struct SteelDynamicComponent {
|
|
|
|
render: SteelVal,
|
|
|
|
render: SteelVal,
|
|
|
|
cursor: Option<SteelVal>,
|
|
|
|
cursor: Option<SteelVal>,
|
|
|
|
required_size: Option<SteelVal>,
|
|
|
|
required_size: Option<SteelVal>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cached key event; we keep this around so that when sending
|
|
|
|
|
|
|
|
// events to the event handler, we can reuse the heap allocation
|
|
|
|
|
|
|
|
// instead of re-allocating for every event (which might be a lot)
|
|
|
|
|
|
|
|
key_event: Option<SteelVal>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl SteelDynamicComponent {
|
|
|
|
impl SteelDynamicComponent {
|
|
|
@ -42,21 +242,16 @@ impl SteelDynamicComponent {
|
|
|
|
render: SteelVal,
|
|
|
|
render: SteelVal,
|
|
|
|
h: HashMap<String, SteelVal>,
|
|
|
|
h: HashMap<String, SteelVal>,
|
|
|
|
) -> Self {
|
|
|
|
) -> Self {
|
|
|
|
// if let SteelVal::HashMapV(h) = functions {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
name,
|
|
|
|
_name: name,
|
|
|
|
state,
|
|
|
|
state,
|
|
|
|
render,
|
|
|
|
render,
|
|
|
|
handle_event: h.get("handle_event").cloned(),
|
|
|
|
handle_event: h.get("handle_event").cloned(),
|
|
|
|
should_update: h.get("should_update").cloned(),
|
|
|
|
should_update: h.get("should_update").cloned(),
|
|
|
|
cursor: h.get("cursor").cloned(),
|
|
|
|
cursor: h.get("cursor").cloned(),
|
|
|
|
required_size: h.get("required_size").cloned(),
|
|
|
|
required_size: h.get("required_size").cloned(),
|
|
|
|
|
|
|
|
key_event: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// panic!("Implement better error handling")
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new_dyn(
|
|
|
|
pub fn new_dyn(
|
|
|
@ -102,67 +297,15 @@ impl Custom for SteelDynamicComponent {}
|
|
|
|
|
|
|
|
|
|
|
|
impl Custom for Box<dyn Component> {}
|
|
|
|
impl Custom for Box<dyn Component> {}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct WrappedDynComponent {
|
|
|
|
#[derive(Clone)]
|
|
|
|
inner: Option<Box<dyn Component>>,
|
|
|
|
enum SteelEventResult {
|
|
|
|
}
|
|
|
|
Consumed,
|
|
|
|
|
|
|
|
Ignored,
|
|
|
|
impl Custom for WrappedDynComponent {}
|
|
|
|
Close,
|
|
|
|
|
|
|
|
|
|
|
|
struct BoxDynComponent {
|
|
|
|
|
|
|
|
inner: Box<dyn Component>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl BoxDynComponent {
|
|
|
|
|
|
|
|
pub fn new(inner: Box<dyn Component>) -> Self {
|
|
|
|
|
|
|
|
Self { inner }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Component for BoxDynComponent {
|
|
|
|
impl Custom for SteelEventResult {}
|
|
|
|
fn handle_event(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
_event: &helix_view::input::Event,
|
|
|
|
|
|
|
|
_ctx: &mut compositor::Context,
|
|
|
|
|
|
|
|
) -> compositor::EventResult {
|
|
|
|
|
|
|
|
self.inner.handle_event(_event, _ctx)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn should_update(&self) -> bool {
|
|
|
|
|
|
|
|
self.inner.should_update()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn cursor(
|
|
|
|
|
|
|
|
&self,
|
|
|
|
|
|
|
|
_area: helix_view::graphics::Rect,
|
|
|
|
|
|
|
|
_ctx: &Editor,
|
|
|
|
|
|
|
|
) -> (
|
|
|
|
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
self.inner.cursor(_area, _ctx)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn required_size(&mut self, _viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|
|
|
|
|
|
|
self.inner.required_size(_viewport)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
|
|
|
|
std::any::type_name::<Self>()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn id(&self) -> Option<&'static str> {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn render(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
area: helix_view::graphics::Rect,
|
|
|
|
|
|
|
|
frame: &mut tui::buffer::Buffer,
|
|
|
|
|
|
|
|
ctx: &mut compositor::Context,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
self.inner.render(area, frame, ctx)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for SteelDynamicComponent {
|
|
|
|
impl Component for SteelDynamicComponent {
|
|
|
|
fn render(
|
|
|
|
fn render(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
@ -181,10 +324,10 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
|
|
|
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// attempting to render
|
|
|
|
// attempting to render
|
|
|
|
let thunk = |engine: &mut Engine, f, c| {
|
|
|
|
let thunk = |engine: &mut Engine, f| {
|
|
|
|
engine.call_function_with_args(
|
|
|
|
engine.call_function_with_args(
|
|
|
|
self.render.clone(),
|
|
|
|
self.render.clone(),
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), f, c],
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), f],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -196,16 +339,15 @@ impl Component for SteelDynamicComponent {
|
|
|
|
.consume(|engine, args| {
|
|
|
|
.consume(|engine, args| {
|
|
|
|
let mut arg_iter = args.into_iter();
|
|
|
|
let mut arg_iter = args.into_iter();
|
|
|
|
|
|
|
|
|
|
|
|
(thunk)(engine, arg_iter.next().unwrap(), arg_iter.next().unwrap())
|
|
|
|
let buffer = arg_iter.next().unwrap();
|
|
|
|
})
|
|
|
|
let context = arg_iter.next().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
engine.update_value("*helix.cx*", context);
|
|
|
|
|
|
|
|
|
|
|
|
// .run_with_references::<tui::buffer::Buffer, tui::buffer::Buffer, Context, Context>(
|
|
|
|
(thunk)(engine, buffer)
|
|
|
|
// frame, &mut ctx, thunk,
|
|
|
|
})
|
|
|
|
// )
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("Calling dynamic render!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Pass in event as well? Need to have immutable reference type
|
|
|
|
// TODO: Pass in event as well? Need to have immutable reference type
|
|
|
@ -213,7 +355,7 @@ impl Component for SteelDynamicComponent {
|
|
|
|
// Clong is _not_ ideal, but it might be all we can do for now.
|
|
|
|
// Clong is _not_ ideal, but it might be all we can do for now.
|
|
|
|
fn handle_event(
|
|
|
|
fn handle_event(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
event: &helix_view::input::Event,
|
|
|
|
event: &Event,
|
|
|
|
ctx: &mut compositor::Context,
|
|
|
|
ctx: &mut compositor::Context,
|
|
|
|
) -> compositor::EventResult {
|
|
|
|
) -> compositor::EventResult {
|
|
|
|
if let Some(handle_event) = &mut self.handle_event {
|
|
|
|
if let Some(handle_event) = &mut self.handle_event {
|
|
|
@ -226,29 +368,70 @@ impl Component for SteelDynamicComponent {
|
|
|
|
jobs: ctx.jobs,
|
|
|
|
jobs: ctx.jobs,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("Handling custom event: {:?}", event);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match self.key_event.as_mut() {
|
|
|
|
|
|
|
|
Some(SteelVal::Custom(key_event)) => {
|
|
|
|
|
|
|
|
// Save the headache, reuse the allocation
|
|
|
|
|
|
|
|
if let Some(inner) = steel::rvals::as_underlying_type_mut::<Event>(
|
|
|
|
|
|
|
|
key_event.borrow_mut().as_mut(),
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
*inner = event.clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
None => {
|
|
|
|
|
|
|
|
self.key_event = Some(event.clone().into_steelval().unwrap());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
|
|
|
|
panic!("This event needs to stay as a steelval");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// attempting to render
|
|
|
|
// attempting to render
|
|
|
|
let thunk = |engine: &mut Engine, c| {
|
|
|
|
let thunk = |engine: &mut Engine| {
|
|
|
|
engine.call_function_with_args(
|
|
|
|
engine.call_function_with_args(
|
|
|
|
handle_event.clone(),
|
|
|
|
handle_event.clone(),
|
|
|
|
vec![
|
|
|
|
vec![self.state.clone(), self.key_event.clone().unwrap()],
|
|
|
|
self.state.clone(),
|
|
|
|
|
|
|
|
// TODO: We do _not_ want to clone here, we would need to create a bunch of methods on the engine for various
|
|
|
|
|
|
|
|
// combinations of reference passing to do this safely. Right now its limited to mutable references, but we should
|
|
|
|
|
|
|
|
// expose more - investigate macros on how to do that with recursively crunching the list to generate the combinations.
|
|
|
|
|
|
|
|
// Experimentation needed.
|
|
|
|
|
|
|
|
event.clone().into_steelval().unwrap(),
|
|
|
|
|
|
|
|
c,
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let close_fn = compositor::EventResult::Consumed(Some(Box::new(
|
|
|
|
|
|
|
|
|compositor: &mut compositor::Compositor, _| {
|
|
|
|
|
|
|
|
// remove the layer
|
|
|
|
|
|
|
|
compositor.pop();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event = match event {
|
|
|
|
|
|
|
|
Event::Key(event) => *event,
|
|
|
|
|
|
|
|
_ => return compositor::EventResult::Ignored(None),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
x.borrow_mut()
|
|
|
|
x.borrow_mut()
|
|
|
|
.run_thunk_with_reference::<Context, Context>(&mut ctx, thunk)
|
|
|
|
.with_mut_reference::<Context, Context>(&mut ctx)
|
|
|
|
|
|
|
|
.consume(move |engine, arguments| {
|
|
|
|
|
|
|
|
let context = arguments[0].clone();
|
|
|
|
|
|
|
|
engine.update_value("*helix.cx*", context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thunk(engine)
|
|
|
|
|
|
|
|
})
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
Ok(v) => compositor::EventResult::from_steelval(&v)
|
|
|
|
Ok(v) => {
|
|
|
|
.unwrap_or_else(|_| compositor::EventResult::Ignored(None)),
|
|
|
|
let value = SteelEventResult::from_steelval(&v);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match value {
|
|
|
|
|
|
|
|
Ok(SteelEventResult::Close) => close_fn,
|
|
|
|
|
|
|
|
Ok(SteelEventResult::Consumed) => compositor::EventResult::Consumed(None),
|
|
|
|
|
|
|
|
Ok(SteelEventResult::Ignored) => compositor::EventResult::Ignored(None),
|
|
|
|
|
|
|
|
_ => match event {
|
|
|
|
|
|
|
|
ctrl!('c') | key!(Esc) => close_fn,
|
|
|
|
|
|
|
|
_ => compositor::EventResult::Ignored(None),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Err(_) => compositor::EventResult::Ignored(None),
|
|
|
|
Err(_) => compositor::EventResult::Ignored(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -259,8 +442,11 @@ impl Component for SteelDynamicComponent {
|
|
|
|
fn should_update(&self) -> bool {
|
|
|
|
fn should_update(&self) -> bool {
|
|
|
|
if let Some(should_update) = &self.should_update {
|
|
|
|
if let Some(should_update) = &self.should_update {
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
x.borrow_mut()
|
|
|
|
let res = x
|
|
|
|
.call_function_with_args(should_update.clone(), vec![self.state.clone()])
|
|
|
|
.borrow_mut()
|
|
|
|
|
|
|
|
.call_function_with_args(should_update.clone(), vec![self.state.clone()]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
Ok(v) => bool::from_steelval(&v).unwrap_or(true),
|
|
|
|
Ok(v) => bool::from_steelval(&v).unwrap_or(true),
|
|
|
|
Err(_) => true,
|
|
|
|
Err(_) => true,
|
|
|
@ -274,30 +460,29 @@ impl Component for SteelDynamicComponent {
|
|
|
|
fn cursor(
|
|
|
|
fn cursor(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
area: helix_view::graphics::Rect,
|
|
|
|
area: helix_view::graphics::Rect,
|
|
|
|
ctx: &Editor,
|
|
|
|
_ctx: &Editor,
|
|
|
|
) -> (
|
|
|
|
) -> (
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
log::info!("Calling cursor with area: {:?}", area);
|
|
|
|
if let Some(cursor) = &self.cursor {
|
|
|
|
if let Some(cursor) = &self.cursor {
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
// attempting to render
|
|
|
|
// attempting to render
|
|
|
|
let thunk = |engine: &mut Engine, e| {
|
|
|
|
let thunk = |engine: &mut Engine| {
|
|
|
|
engine.call_function_with_args(
|
|
|
|
engine.call_function_with_args(
|
|
|
|
cursor.clone(),
|
|
|
|
cursor.clone(),
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), e],
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap()],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
<(
|
|
|
|
let result = Option::<helix_core::Position>::from_steelval(
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
&ENGINE.with(|x| thunk(&mut (x.borrow_mut())).unwrap()),
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
);
|
|
|
|
)>::from_steelval(&ENGINE.with(|x| {
|
|
|
|
|
|
|
|
x.borrow_mut()
|
|
|
|
log::info!("Setting cursor at position: {:?}", result);
|
|
|
|
.run_thunk_with_ro_reference::<Editor, Editor>(ctx, thunk)
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
(result.unwrap(), CursorKind::Block)
|
|
|
|
}))
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
(None, helix_view::graphics::CursorKind::Hidden)
|
|
|
|
(None, helix_view::graphics::CursorKind::Hidden)
|
|
|
|
}
|
|
|
|
}
|
|
|
|