Implement term_view resize properly
This commit is contained in:
		
							parent
							
								
									c117482d4f
								
							
						
					
					
						commit
						adaabcc6c2
					
				
							
								
								
									
										74
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										74
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -30,12 +30,6 @@ dependencies = [
 | 
			
		||||
 "zerocopy",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "aliasable"
 | 
			
		||||
version = "0.1.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "allocator-api2"
 | 
			
		||||
version = "0.2.18"
 | 
			
		||||
@ -649,12 +643,6 @@ dependencies = [
 | 
			
		||||
 "allocator-api2",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "heck"
 | 
			
		||||
version = "0.4.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hermit-abi"
 | 
			
		||||
version = "0.3.9"
 | 
			
		||||
@ -716,15 +704,6 @@ dependencies = [
 | 
			
		||||
 "hashbrown",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "itertools"
 | 
			
		||||
version = "0.12.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "either",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "itertools"
 | 
			
		||||
version = "0.13.0"
 | 
			
		||||
@ -825,31 +804,6 @@ version = "1.19.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ouroboros"
 | 
			
		||||
version = "0.18.4"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "944fa20996a25aded6b4795c6d63f10014a7a83f8be9828a11860b08c5fc4a67"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "aliasable",
 | 
			
		||||
 "ouroboros_macro",
 | 
			
		||||
 "static_assertions",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ouroboros_macro"
 | 
			
		||||
version = "0.18.4"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "39b0deead1528fd0e5947a8546a9642a9777c25f6e1e26f34c97b204bbb465bd"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "heck",
 | 
			
		||||
 "itertools 0.12.1",
 | 
			
		||||
 "proc-macro2",
 | 
			
		||||
 "proc-macro2-diagnostics",
 | 
			
		||||
 "quote",
 | 
			
		||||
 "syn 2.0.73",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "percent-encoding"
 | 
			
		||||
version = "2.3.1"
 | 
			
		||||
@ -976,19 +930,6 @@ dependencies = [
 | 
			
		||||
 "unicode-ident",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "proc-macro2-diagnostics"
 | 
			
		||||
version = "0.10.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "proc-macro2",
 | 
			
		||||
 "quote",
 | 
			
		||||
 "syn 2.0.73",
 | 
			
		||||
 "version_check",
 | 
			
		||||
 "yansi",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "prokio"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
@ -1163,12 +1104,6 @@ version = "0.3.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "static_assertions"
 | 
			
		||||
version = "1.1.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "syn"
 | 
			
		||||
version = "1.0.109"
 | 
			
		||||
@ -1418,10 +1353,9 @@ dependencies = [
 | 
			
		||||
 "anyhow",
 | 
			
		||||
 "console_error_panic_hook",
 | 
			
		||||
 "im",
 | 
			
		||||
 "itertools 0.13.0",
 | 
			
		||||
 "itertools",
 | 
			
		||||
 "minicrossterm",
 | 
			
		||||
 "nom",
 | 
			
		||||
 "ouroboros",
 | 
			
		||||
 "piccolo",
 | 
			
		||||
 "thiserror",
 | 
			
		||||
 "unicode-segmentation",
 | 
			
		||||
@ -1431,12 +1365,6 @@ dependencies = [
 | 
			
		||||
 "yew",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "yansi"
 | 
			
		||||
version = "1.0.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "yew"
 | 
			
		||||
version = "0.21.0"
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,9 @@ piccolo = "0.3.3"
 | 
			
		||||
unicode-segmentation = "1.11.0"
 | 
			
		||||
unicode-width = "0.1.13"
 | 
			
		||||
wasm-bindgen = "0.2.92"
 | 
			
		||||
web-sys = "0.3.69"
 | 
			
		||||
web-sys = { version = "0.3.69", features = ["ResizeObserver"] }
 | 
			
		||||
yew = { version = "0.21.0", features = ["csr"] }
 | 
			
		||||
minicrossterm = { git = "https://git.blastmud.org/blasthavers/minicrossterm.git", rev = "494f89daef41162fbd89d5266e261018ed5ff6dc" }
 | 
			
		||||
thiserror = "1.0.63"
 | 
			
		||||
console_error_panic_hook = "0.1.7"
 | 
			
		||||
ouroboros = "0.18.4"
 | 
			
		||||
anyhow = "1.0.86"
 | 
			
		||||
 | 
			
		||||
@ -498,6 +498,11 @@ impl Readline {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn handle_resize(&mut self, term_size: (u16, u16)) -> Result<(), ReadlineError> {
 | 
			
		||||
        web_sys::console::log_3(
 | 
			
		||||
            &"Doing resize event".into(),
 | 
			
		||||
            &term_size.0.into(),
 | 
			
		||||
            &term_size.1.into(),
 | 
			
		||||
        );
 | 
			
		||||
        self.line_state.handle_event(
 | 
			
		||||
            Event::Resize(term_size.0, term_size.1),
 | 
			
		||||
            &mut self.write_term,
 | 
			
		||||
 | 
			
		||||
@ -74,7 +74,11 @@ pub struct TermFrameData {
 | 
			
		||||
    pub fit: FitAddon,
 | 
			
		||||
    pub node: Node,
 | 
			
		||||
    pub readline: Readline,
 | 
			
		||||
    pub retained_closures: Option<(Closure<dyn FnMut(String)>, Closure<dyn FnMut(Dims)>)>,
 | 
			
		||||
    pub retained_closures: Option<(
 | 
			
		||||
        Closure<dyn FnMut(String)>,
 | 
			
		||||
        Closure<dyn FnMut(Dims)>,
 | 
			
		||||
        Closure<dyn FnMut(JsValue) -> JsValue>,
 | 
			
		||||
    )>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl PartialEq for TermFrameData {
 | 
			
		||||
@ -100,6 +104,16 @@ fn get_or_make_term_frame<'a>(
 | 
			
		||||
            .and_then(|d| d.create_element("div").ok())
 | 
			
		||||
            .expect("Can create element for term");
 | 
			
		||||
        element.set_class_name("hterminal");
 | 
			
		||||
 | 
			
		||||
        let fit_for_resize = FitAddon { obj: fit.clone() };
 | 
			
		||||
        let resize_element_closure: Closure<dyn FnMut(JsValue) -> JsValue> =
 | 
			
		||||
            Closure::new(move |_: JsValue| {
 | 
			
		||||
                fit_for_resize.fit();
 | 
			
		||||
                JsValue::TRUE
 | 
			
		||||
            });
 | 
			
		||||
        web_sys::ResizeObserver::new(resize_element_closure.as_ref().unchecked_ref())
 | 
			
		||||
            .expect("Couldn't construct ResizeObserver")
 | 
			
		||||
            .observe(&element);
 | 
			
		||||
        term.open(&element);
 | 
			
		||||
        term.loadAddon(&fit);
 | 
			
		||||
        fit.fit();
 | 
			
		||||
@ -128,6 +142,7 @@ fn get_or_make_term_frame<'a>(
 | 
			
		||||
        let frame_for_resize: TermFrame = frame.clone();
 | 
			
		||||
        let globals_for_resize: GlobalCell = globals.clone();
 | 
			
		||||
        let resize_closure = Closure::new(move |dims: Dims| {
 | 
			
		||||
            web_sys::console::log_1(&"Resize closure called".into());
 | 
			
		||||
            globals_for_resize
 | 
			
		||||
                .frame_registry
 | 
			
		||||
                .try_borrow_mut()
 | 
			
		||||
@ -175,7 +190,7 @@ fn get_or_make_term_frame<'a>(
 | 
			
		||||
        term.onData(&data_closure);
 | 
			
		||||
        new_data
 | 
			
		||||
            .retained_closures
 | 
			
		||||
            .replace((data_closure, resize_closure));
 | 
			
		||||
            .replace((data_closure, resize_closure, resize_element_closure));
 | 
			
		||||
 | 
			
		||||
        new_data
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user