2024-08-16 21:39:39 +10:00
|
|
|
use std::cell::RefCell;
|
2024-07-21 17:01:56 +10:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
use yew::prelude::*;
|
|
|
|
|
2024-08-16 21:39:39 +10:00
|
|
|
pub mod command_handler;
|
|
|
|
pub mod lineengine;
|
|
|
|
pub mod lua_state;
|
|
|
|
pub mod parsing;
|
2024-08-21 21:28:27 +10:00
|
|
|
pub mod split_panel;
|
2024-07-21 17:01:56 +10:00
|
|
|
pub mod term_view;
|
2024-08-16 23:22:21 +10:00
|
|
|
use crate::lua_state::{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-08-16 21:39:39 +10:00
|
|
|
#[derive(Properties)]
|
2024-08-16 23:22:21 +10:00
|
|
|
pub struct GlobalState {
|
|
|
|
// No strong references allowed between each of these groups of state.
|
|
|
|
frame_registry: RefCell<RegisteredTermFrames>,
|
|
|
|
lua_engine: RefCell<LuaState>,
|
2024-08-16 21:39:39 +10:00
|
|
|
}
|
2024-08-16 23:22:21 +10:00
|
|
|
type GlobalCell = Rc<GlobalState>;
|
2024-08-16 21:39:39 +10:00
|
|
|
|
|
|
|
// Used only for yew. Always equal since we don't want it to
|
|
|
|
// actually look into GlobalState, changes there should never
|
|
|
|
// cause a re-render.
|
|
|
|
impl PartialEq for GlobalState {
|
|
|
|
fn eq(&self, _other: &Self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-21 17:01:56 +10:00
|
|
|
#[function_component(App)]
|
|
|
|
fn app() -> Html {
|
2024-08-16 23:22:21 +10:00
|
|
|
let global = use_memo((), |_| GlobalState {
|
2024-08-16 21:39:39 +10:00
|
|
|
frame_registry: RegisteredTermFrames::new().into(),
|
2024-08-16 23:22:21 +10:00
|
|
|
lua_engine: LuaState::setup().expect("Can create interpreter").into(),
|
2024-08-16 21:39:39 +10:00
|
|
|
});
|
2024-08-16 23:22:21 +10:00
|
|
|
install_lua_globals(&global).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">
|
|
|
|
<SplitPanel direction={PanelDirection::Vertical} first={ html! { <TermView terminal={TermFrame(0)} global={global.clone()}/> }}
|
|
|
|
second={ html! { <TermView terminal={TermFrame(1)} global={global.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();
|
|
|
|
}
|