Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 37 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ repository = "https://github.com/orhun/ratzilla"
keywords = ["tui", "webassembly", "ratatui"]
categories = ["wasm"]
include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md"]
edition = "2021"
edition = "2024"

[dependencies]
web-sys = { version = "0.3.81", features = [
web-sys = { version = "0.3.82", features = [
'console',
'CanvasRenderingContext2d',
'Document',
Expand All @@ -40,6 +40,7 @@ web-sys = { version = "0.3.81", features = [
compact_str = "0.9.0"
ratatui = { version = "0.29", default-features = false, features = ["all-widgets"] }
console_error_panic_hook = "0.1.7"
thiserror = "2.0.12"
thiserror = "2.0.17"
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "std"] }
beamterm-renderer = "0.8.0"
bitflags = "2.10.0"
2 changes: 1 addition & 1 deletion src/backend/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use std::io::Result as IoResult;

use crate::{
CursorShape,
backend::{
color::{actual_bg_color, actual_fg_color},
utils::*,
},
error::Error,
CursorShape,
};
use ratatui::{
backend::WindowSize,
Expand Down Expand Up @@ -273,7 +273,7 @@
/// 1. Only processes cells that have changed since the last render.
/// 2. Tracks the last foreground color used to avoid unnecessary style changes
/// 3. Only creates clipping paths for potentially problematic glyphs (non-ASCII)
/// or when `always_clip_cells` is enabled.

Check warning on line 276 in src/backend/canvas.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/backend/canvas.rs:276:9 | 276 | /// or when `always_clip_cells` is enabled. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#doc_lazy_continuation = note: `#[warn(clippy::doc_lazy_continuation)]` on by default help: indent this line | 276 | /// or when `always_clip_cells` is enabled. | +++
fn draw_symbols(&mut self) -> Result<(), Error> {
let changed_cells = &self.changed_cells;
let mut index = 0;
Expand Down Expand Up @@ -405,7 +405,7 @@
fn draw_debug(&mut self) -> Result<(), Error> {
self.canvas.context.save();

let color = self.debug_mode.as_ref().unwrap();

Check warning on line 408 in src/backend/canvas.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on an `Option` value

warning: used `unwrap()` on an `Option` value --> src/backend/canvas.rs:408:21 | 408 | let color = self.debug_mode.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#unwrap_used note: the lint level is defined here --> src/lib.rs:1:23 | 1 | #![warn(missing_docs, clippy::unwrap_used)] | ^^^^^^^^^^^^^^^^^^^
for (y, line) in self.buffer.iter().enumerate() {
for (x, _) in line.iter().enumerate() {
self.canvas.context.set_stroke_style_str(color);
Expand Down
8 changes: 1 addition & 7 deletions src/backend/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ fn indexed_color_to_rgb(index: u8) -> u32 {

// Convert 0-5 range to 0-255 RGB
// Values: 0 -> 0, 1 -> 95, 2 -> 135, 3 -> 175, 4 -> 215, 5 -> 255
let to_rgb = |n: u8| -> u32 {
if n == 0 {
0
} else {
55 + 40 * n as u32
}
};
let to_rgb = |n: u8| -> u32 { if n == 0 { 0 } else { 55 + 40 * n as u32 } };

to_rgb(r) << 16 | to_rgb(g) << 8 | to_rgb(b)
}
Expand Down
7 changes: 4 additions & 3 deletions src/backend/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
prelude::Backend,
};
use web_sys::{
wasm_bindgen::{prelude::Closure, JsCast},
window, Document, Element, Window,
Document, Element, Window,
wasm_bindgen::{JsCast, prelude::Closure},
window,
};

use crate::{backend::utils::*, error::Error, widgets::hyperlink::HYPERLINK_MODIFIER, CursorShape};
use crate::{CursorShape, backend::utils::*, error::Error, widgets::hyperlink::HYPERLINK_MODIFIER};

/// Options for the [`DomBackend`].
#[derive(Debug, Default)]
Expand All @@ -35,7 +36,7 @@
///
/// - If the grid ID is not set, it returns `"grid"`.
/// - If the grid ID is set, it returns the grid ID suffixed with
/// `"_ratzilla_grid"`.

Check warning on line 39 in src/backend/dom.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item overindented

warning: doc list item overindented --> src/backend/dom.rs:39:9 | 39 | /// `"_ratzilla_grid"`. | ^^^^ help: try using ` ` (2 spaces) | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#doc_overindented_list_items = note: `#[warn(clippy::doc_overindented_list_items)]` on by default
pub fn grid_id(&self) -> String {
match &self.grid_id {
Some(id) => format!("{id}_ratzilla_grid"),
Expand Down
5 changes: 3 additions & 2 deletions src/backend/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use crate::{
error::Error,
utils::{get_screen_size, get_window_size, is_mobile},
};
use compact_str::{format_compact, CompactString};
use compact_str::{CompactString, format_compact};
use ratatui::{
buffer::Cell,
style::{Color, Modifier},
};
use web_sys::{
Document, Element, HtmlCanvasElement, Window,
wasm_bindgen::{JsCast, JsValue},
window, Document, Element, HtmlCanvasElement, Window,
window,
};

/// Creates a new `<span>` element with the given cell.
Expand Down
8 changes: 4 additions & 4 deletions src/backend/webgl2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{
CursorShape,
backend::{color::to_rgb, utils::*},
error::Error,
widgets::hyperlink::HYPERLINK_MODIFIER,
CursorShape,
};
use beamterm_renderer::{
mouse::*, select, CellData, GlyphEffect, SelectionMode, Terminal as Beamterm, Terminal,
CellData, GlyphEffect, SelectionMode, Terminal as Beamterm, Terminal, mouse::*, select,
};
use bitvec::prelude::BitVec;
use compact_str::CompactString;
Expand All @@ -17,7 +17,7 @@
style::{Color, Modifier},
};
use std::{cell::RefCell, io::Result as IoResult, mem::swap, rc::Rc};
use web_sys::{wasm_bindgen::JsCast, window, Element};
use web_sys::{Element, wasm_bindgen::JsCast, window};

/// Re-export beamterm's atlas data type. Used by [`WebGl2BackendOptions::font_atlas`].
pub use beamterm_renderer::FontAtlasData;
Expand Down Expand Up @@ -340,11 +340,11 @@
}

// Reset cursor state when canvas is resized
if let Some(cursor_state) = &self.cursor_over_hyperlink {
if let Ok(mut state) = cursor_state.try_borrow_mut() {
*state = false;
}
}

Check warning on line 347 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> src/backend/webgl2.rs:343:9 | 343 | / if let Some(cursor_state) = &self.cursor_over_hyperlink { 344 | | if let Ok(mut state) = cursor_state.try_borrow_mut() { 345 | | *state = false; 346 | | } 347 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 343 ~ if let Some(cursor_state) = &self.cursor_over_hyperlink 344 ~ && let Ok(mut state) = cursor_state.try_borrow_mut() { 345 | *state = false; 346 ~ } |

Ok(())
}
Expand Down Expand Up @@ -431,7 +431,7 @@
c.style(c.get_style() ^ (GlyphEffect::Underline as u16));
}
}
}
};
}

/// Measures the beginning of a performance mark.
Expand Down Expand Up @@ -491,7 +491,7 @@
fn create_hyperlink_mouse_handler(
beamterm: &Beamterm,
hyperlink_cells: Rc<RefCell<BitVec>>,
callback: Rc<RefCell<dyn FnMut(&str)>>,

Check warning on line 494 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> src/backend/webgl2.rs:494:19 | 494 | callback: Rc<RefCell<dyn FnMut(&str)>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
cursor_state: Rc<RefCell<bool>>,
) -> Result<TerminalMouseHandler, Error> {
let grid = beamterm.grid();
Expand All @@ -508,17 +508,17 @@
match event.event_type {
MouseEventType::MouseUp => {
// Handle hyperlink clicks (left mouse button only)
if event.button() == 0 {
if let Some(url) = extract_hyperlink_url(
hyperlink_cells_clone.clone(),
grid,
event.col,
event.row,
) {
if let Ok(mut cb) = callback.try_borrow_mut() {
cb(&url);
}
}

Check warning on line 521 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> src/backend/webgl2.rs:512:29 | 512 | / ... if let Some(url) = extract_hyperlink_url( 513 | | ... hyperlink_cells_clone.clone(), 514 | | ... grid, 515 | | ... event.col, ... | 521 | | ... } | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#collapsible_if help: collapse nested if block | 517 ~ ) 518 ~ && let Ok(mut cb) = callback.try_borrow_mut() { 519 | cb(&url); 520 ~ } |
}

Check warning on line 522 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> src/backend/webgl2.rs:511:25 | 511 | / if event.button() == 0 { 512 | | if let Some(url) = extract_hyperlink_url( 513 | | hyperlink_cells_clone.clone(), 514 | | grid, ... | 522 | | } | |_________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#collapsible_if help: collapse nested if block | 511 ~ if event.button() == 0 512 ~ && let Some(url) = extract_hyperlink_url( 513 | hyperlink_cells_clone.clone(), ... 520 | } 521 ~ } |
}
MouseEventType::MouseMove => {
Expand All @@ -531,12 +531,12 @@
);

// Only update cursor style if state has changed
if let Ok(mut current_state) = cursor_state_clone.try_borrow_mut() {
if *current_state != is_over_hyperlink {
*current_state = is_over_hyperlink;
Self::update_canvas_cursor_style(&canvas_clone, is_over_hyperlink);
}
}

Check warning on line 539 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> src/backend/webgl2.rs:534:25 | 534 | / if let Ok(mut current_state) = cursor_state_clone.try_borrow_mut() { 535 | | if *current_state != is_over_hyperlink { 536 | | *current_state = is_over_hyperlink; 537 | | Self::update_canvas_cursor_style(&canvas_clone, is_over_hyperlink); 538 | | } 539 | | } | |_________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#collapsible_if help: collapse nested if block | 534 ~ if let Ok(mut current_state) = cursor_state_clone.try_borrow_mut() 535 ~ && *current_state != is_over_hyperlink { 536 | *current_state = is_over_hyperlink; 537 | Self::update_canvas_cursor_style(&canvas_clone, is_over_hyperlink); 538 ~ } |
}
_ => {}
}
Expand Down Expand Up @@ -816,7 +816,7 @@
/// A `Debug`-derive friendly convenience wrapper
#[derive(Clone)]
struct HyperlinkCallback {
callback: Rc<RefCell<dyn FnMut(&str)>>,

Check warning on line 819 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> src/backend/webgl2.rs:819:15 | 819 | callback: Rc<RefCell<dyn FnMut(&str)>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#type_complexity
}

impl HyperlinkCallback {
Expand Down
Loading
Loading