Skip to content
Merged
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
2 changes: 1 addition & 1 deletion examples/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Cli {
}

fn main() -> Result<()> {
let app_state = Rc::new(RefCell::new(App::new("Demo", false)));
let app_state = Rc::new(RefCell::new(App::new("Demo", true)));

// Create backend with explicit size like main branch (1600x900)
let canvas_options = CanvasBackendOptions::new()
Expand Down
17 changes: 16 additions & 1 deletion src/backend/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@
modifier_style.push_str("text-decoration: line-through; ");
}

format!("{fg_style} {bg_style} {modifier_style}")
// ensure consistent width for braille characters
let braille_style = if contains_braille(cell) {
"display: inline-block; width: 1ch; font-variant-numeric: tabular-nums; "
} else {
""
};

format!("{fg_style} {bg_style} {modifier_style}{braille_style}")
}

/// Converts a Color to a CSS style.
pub(crate) fn get_canvas_color(color: Color, fallback_color: Color) -> CompactString {
let color = ansi_to_rgb(color).unwrap_or_else(|| ansi_to_rgb(fallback_color).unwrap());

Check warning on line 99 in src/backend/utils.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/utils.rs:99:54 | 99 | let color = ansi_to_rgb(color).unwrap_or_else(|| ansi_to_rgb(fallback_color).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/master/index.html#unwrap_used

format_compact!("rgb({}, {}, {})", color.0, color.1, color.2)
}
Expand All @@ -112,8 +119,8 @@

/// Returns the number of pixels that can fit in the window.
pub(crate) fn get_raw_screen_size() -> (i32, i32) {
let s = web_sys::window().unwrap().screen().unwrap();

Check warning on line 122 in src/backend/utils.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/utils.rs:122:13 | 122 | let s = web_sys::window().unwrap().screen().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/master/index.html#unwrap_used

Check warning on line 122 in src/backend/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on a `Result` value

warning: used `unwrap()` on a `Result` value --> src/backend/utils.rs:122:13 | 122 | let s = web_sys::window().unwrap().screen().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if this value is an `Err`, 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/master/index.html#unwrap_used
(s.width().unwrap(), s.height().unwrap())

Check warning on line 123 in src/backend/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on a `Result` value

warning: used `unwrap()` on a `Result` value --> src/backend/utils.rs:123:26 | 123 | (s.width().unwrap(), s.height().unwrap()) | ^^^^^^^^^^^^^^^^^^^ | = note: if this value is an `Err`, 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/master/index.html#unwrap_used

Check warning on line 123 in src/backend/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on a `Result` value

warning: used `unwrap()` on a `Result` value --> src/backend/utils.rs:123:6 | 123 | (s.width().unwrap(), s.height().unwrap()) | ^^^^^^^^^^^^^^^^^^ | = note: if this value is an `Err`, 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/master/index.html#unwrap_used
}

/// Returns a buffer based on the screen size.
Expand Down Expand Up @@ -160,9 +167,9 @@

/// Returns the performance object from the window.
pub(crate) fn performance() -> Result<web_sys::Performance, Error> {
Ok(get_window()?
.performance()
.ok_or(Error::UnableToRetrieveComponent("Performance"))?)

Check warning on line 172 in src/backend/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

enclosing `Ok` and `?` operator are unneeded

warning: enclosing `Ok` and `?` operator are unneeded --> src/backend/utils.rs:170:5 | 170 | / Ok(get_window()? 171 | | .performance() 172 | | .ok_or(Error::UnableToRetrieveComponent("Performance"))?) | |_________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark = note: `#[warn(clippy::needless_question_mark)]` on by default help: remove the enclosing `Ok` and `?` operator | 170 ~ get_window()? 171 | .performance() 172 ~ .ok_or(Error::UnableToRetrieveComponent("Performance")) |
}

/// Creates a new canvas element in the specified parent element with the
Expand All @@ -186,3 +193,11 @@

Ok(canvas)
}

/// Checks if the given cell contains a braille character.
fn contains_braille(cell: &Cell) -> bool {
cell.symbol()
.chars()
.next()
.is_some_and(|c| ('\u{2800}'..='\u{28FF}').contains(&c))
}
Loading