Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): add tartaros terminal #3044

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

not-nullptr
Copy link
Contributor

This PR swaps out the previous terminal on the server panel for Tartaros, a new WASM + Rust based terminal authored internally by the Pyro team.

It includes near feature parity with the current terminal implementation, including virtualization and ANSI support. It also supports the more primitive feature you'd expect, like a scroll bar with mouse wheel support, and line-breaking.

In terms of benefits, this terminal can remain locked at the user's refresh rate scaling up to millions of lines, whilst also removing all previous jank that came with line-breaking and virtualization on the previous implementation.

This is a draft for 3 reasons:

  1. Some visual features remain unimplemented (dark mode, progressive blur on scroll, proper fullscreen support, HiDPI)
  2. It currently does not build due to vite-plugin-wasm not being recognized at build time.
  3. There are still some issues with scrolling on mobile + touchpad-based devices.

@not-nullptr not-nullptr marked this pull request as draft December 20, 2024 15:50
Comment on lines 96 to 215
// };

// _state
// .borrow()
// .canvas
// .add_event_listener_with_callback("wheel", closure.as_ref().unchecked_ref())
// .expect("failed to add wheel listener");

// closure.forget();

// let closure = {
// let state = _state.clone();
// Closure::<dyn FnMut(_)>::new(move |event: web_sys::MouseEvent| {
// let mut state = state.borrow_mut();
// let total_lines = (state.lines.len() - LINES_VISIBLE) as u64;
// let height = state.canvas.height() as f64;
// let total_height = (LINE_HEIGHT as f64) * total_lines as f64;
// let scroll_bar_height = cmp::max(
// (height / total_height * height).round() as u64,
// MIN_SCROLL_BAR_HEIGHT as u64,
// );
// let scroll_bar_y =
// (height - scroll_bar_height as f64) * state.offset as f64 / total_lines as f64;

// let (x, y) = (event.client_x() as f64, event.client_y() as f64);
// let rect = state.canvas.get_bounding_client_rect();
// let (x, y) = (x - rect.left(), y - rect.top());
// // if the mouse isn't inside the scroll bar, return
// // scrollbar width should be accounted for
// if x < rect.width() as f64 - SCROLL_BAR_WIDTH as f64 {
// state.scroll_bar_y_offset = -1.0;
// return;
// }
// if y < scroll_bar_y || y > scroll_bar_y + scroll_bar_height as f64 {
// state.scroll_bar_y_offset = (scroll_bar_height as f64) / 2.0;
// state.offset = PyroConsole::calculate_offset(
// y - scroll_bar_height as f64 / 2.0,
// rect.height(),
// (state.lines.len() - LINES_VISIBLE) as u64,
// );
// } else {
// state.scroll_bar_y_offset = y - scroll_bar_y;
// }
// })
// };

// _state
// .borrow()
// .canvas
// .add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())
// .expect("failed to add mousedown listener");

// closure.forget();

// let closure = {
// let state = _state.clone();
// Closure::<dyn FnMut(_)>::new(move |event: web_sys::MouseEvent| {
// let mut state = state.borrow_mut();
// if state.scroll_bar_y_offset < 0.0 {
// return;
// }
// let y = event.client_y() - state.scroll_bar_y_offset as i32;
// let rect = state.canvas.get_bounding_client_rect();
// let y = y - rect.top() as i32;

// // for debugging, just scroll anyway
// // figure out what offset we need for the current y position -- the top pixel of the
// // scroll bar should be at the current y position (approximately)
// let offset = PyroConsole::calculate_offset(
// y as f64,
// rect.height(),
// (state.lines.len() - LINES_VISIBLE) as u64,
// );
// state.offset = offset;
// })
// };

// _state
// .borrow()
// .window
// .add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref())
// .expect("failed to add mousemove listener");

// closure.forget();

// let closure = {
// let state = _state.clone();
// Closure::<dyn FnMut(_)>::new(move |_: web_sys::MouseEvent| {
// let mut state = state.borrow_mut();
// state.scroll_bar_y_offset = -1.0;
// })
// };

// _state
// .borrow()
// .window
// .add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())
// .expect("failed to add mouseup listener");

// closure.forget();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan on reusing any of this further on in this PR? Otherwise I think this massive comment should probably be removed before this gets approved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yah this was all old migration code for when i was moving it off the ui thread into a web worker. will remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants