2024-08-16 21:39:39 +10:00
|
|
|
use std::cell::RefCell;
|
2024-07-21 17:01:56 +10:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2024-08-22 22:25:05 +10:00
|
|
|
use term_split::TermSplit;
|
2024-07-21 17:01:56 +10:00
|
|
|
use yew::prelude::*;
|
|
|
|
|
2024-08-16 21:39:39 +10:00
|
|
|
pub mod command_handler;
|
2024-09-07 00:17:16 +10:00
|
|
|
pub mod id_intern;
|
2024-08-16 21:39:39 +10:00
|
|
|
pub mod lineengine;
|
2024-09-07 22:05:01 +10:00
|
|
|
pub mod lua_engine;
|
2024-08-16 21:39:39 +10:00
|
|
|
pub mod parsing;
|
2024-08-21 21:28:27 +10:00
|
|
|
pub mod split_panel;
|
2024-08-22 22:25:05 +10:00
|
|
|
pub mod term_split;
|
2024-07-21 17:01:56 +10:00
|
|
|
pub mod term_view;
|
2024-09-06 17:37:43 +10:00
|
|
|
pub mod websocket;
|
2024-09-07 22:05:01 +10:00
|
|
|
use crate::lua_engine::{install_lua_globals, LuaState};
|
2024-08-21 21:28:27 +10:00
|
|
|
use crate::split_panel::*;
|
2024-07-21 17:01:56 +10:00
|
|
|
use crate::term_view::*;
|
2024-09-06 17:37:43 +10:00
|
|
|
use crate::websocket::RegisteredWebSockets;
|
2024-07-21 17:01:56 +10:00
|
|
|
|
2024-08-16 21:39:39 +10:00
|
|
|
#[derive(Properties)]
|
2024-08-23 23:37:58 +10:00
|
|
|
pub struct GlobalMemoState {
|
2024-08-16 23:22:21 +10:00
|
|
|
// No strong references allowed between each of these groups of state.
|
|
|
|
frame_registry: RefCell<RegisteredTermFrames>,
|
|
|
|
lua_engine: RefCell<LuaState>,
|
2024-09-06 17:37:43 +10:00
|
|
|
ws_registry: RefCell<RegisteredWebSockets>,
|
2024-08-23 23:37:58 +10:00
|
|
|
|
|
|
|
// A cache of the latest layout info (separate from the state).
|
|
|
|
// Updating this doesn't force a relayout, so only update the cache when
|
|
|
|
// you also emit a change to the real layout.
|
|
|
|
layout: RefCell<Rc<GlobalLayoutState>>,
|
2024-08-16 21:39:39 +10:00
|
|
|
}
|
2024-08-23 23:37:58 +10:00
|
|
|
type GlobalMemoCell = Rc<GlobalMemoState>;
|
2024-08-16 21:39:39 +10:00
|
|
|
|
2024-08-23 23:37:58 +10:00
|
|
|
// Used only for yew. Lua and Frame Registry excluded, as
|
|
|
|
// changes there should never cause a re-render.
|
|
|
|
impl PartialEq for GlobalMemoState {
|
2024-08-16 21:39:39 +10:00
|
|
|
fn eq(&self, _other: &Self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-23 23:37:58 +10:00
|
|
|
// Used for state that impacts the entire layout. Changes here will
|
|
|
|
// cause a re-render
|
|
|
|
#[derive(PartialEq, Properties)]
|
|
|
|
pub struct GlobalLayoutState {
|
|
|
|
term_splits: TermSplit,
|
|
|
|
}
|
|
|
|
// Note: Despite interior mutability, you still should always call the
|
|
|
|
// setter to force a re-render. Interior mutability is used to allow this
|
|
|
|
// to be baked into the Lua closures and still allow access to the current
|
|
|
|
// value.
|
|
|
|
type GlobalLayoutCell = Rc<GlobalLayoutState>;
|
|
|
|
|
2024-07-21 17:01:56 +10:00
|
|
|
#[function_component(App)]
|
|
|
|
fn app() -> Html {
|
2024-08-23 23:37:58 +10:00
|
|
|
let global_layout: UseStateHandle<GlobalLayoutCell> = use_state(|| {
|
|
|
|
Rc::new(GlobalLayoutState {
|
|
|
|
term_splits: TermSplit::Term {
|
|
|
|
frame: TermFrame(1),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
});
|
|
|
|
let global_memo = use_memo((), |_| GlobalMemoState {
|
2024-08-16 21:39:39 +10:00
|
|
|
frame_registry: RegisteredTermFrames::new().into(),
|
2024-09-06 17:37:43 +10:00
|
|
|
ws_registry: RegisteredWebSockets::new().into(),
|
2024-08-16 23:22:21 +10:00
|
|
|
lua_engine: LuaState::setup().expect("Can create interpreter").into(),
|
2024-08-23 23:37:58 +10:00
|
|
|
layout: RefCell::new((*global_layout).clone()),
|
|
|
|
});
|
|
|
|
use_memo((), |_| {
|
|
|
|
install_lua_globals(&global_memo, global_layout.setter())
|
|
|
|
.expect("Couldn't install Lua globals")
|
2024-08-16 21:39:39 +10:00
|
|
|
});
|
|
|
|
|
2024-07-21 17:01:56 +10:00
|
|
|
html! {
|
2024-08-21 21:28:27 +10:00
|
|
|
<div class="toplevel">
|
2024-08-23 23:37:58 +10:00
|
|
|
<TermViewTree global_memo={global_memo.clone()}
|
|
|
|
global_layout={global_layout.clone()}/>
|
2024-07-21 17:01:56 +10:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2024-08-16 21:39:39 +10:00
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
2024-07-21 17:01:56 +10:00
|
|
|
yew::Renderer::<App>::new().render();
|
|
|
|
}
|