worldwideportal/src/main.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

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::*;
pub mod command_handler;
pub mod lineengine;
pub mod lua_state;
pub mod parsing;
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;
use crate::lua_state::{install_lua_globals, LuaState};
use crate::split_panel::*;
2024-07-21 17:01:56 +10:00
use crate::term_view::*;
#[derive(Properties)]
pub struct GlobalState {
// No strong references allowed between each of these groups of state.
frame_registry: RefCell<RegisteredTermFrames>,
lua_engine: RefCell<LuaState>,
2024-08-22 22:25:05 +10:00
term_splits: RefCell<TermSplit>,
}
type GlobalCell = Rc<GlobalState>;
// 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 {
let global = use_memo((), |_| GlobalState {
frame_registry: RegisteredTermFrames::new().into(),
lua_engine: LuaState::setup().expect("Can create interpreter").into(),
2024-08-22 22:25:05 +10:00
term_splits: TermSplit::Term {
frame: TermFrame(1),
}
.into(),
});
install_lua_globals(&global).expect("Couldn't install Lua globals");
2024-07-21 17:01:56 +10:00
html! {
<div class="toplevel">
2024-08-22 22:25:05 +10:00
<TermViewTree global={global.clone()}/>
2024-07-21 17:01:56 +10:00
</div>
}
}
fn main() {
console_error_panic_hook::set_once();
2024-07-21 17:01:56 +10:00
yew::Renderer::<App>::new().render();
}