1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 08:25:50 +03:00

term: improve readability of error message for oversized image

refs: https://github.com/wez/wezterm/issues/3264
This commit is contained in:
Wez Furlong 2023-03-16 22:41:52 -07:00
parent a115fc0df7
commit 97452d0ccc
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 22 additions and 3 deletions

16
Cargo.lock generated
View File

@ -2126,6 +2126,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humansize"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
dependencies = [
"libm",
]
[[package]] [[package]]
name = "humantime" name = "humantime"
version = "2.1.0" version = "2.1.0"
@ -2537,6 +2546,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "libm"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb"
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.24.2" version = "0.24.2"
@ -6064,6 +6079,7 @@ dependencies = [
"env_logger", "env_logger",
"finl_unicode", "finl_unicode",
"hex", "hex",
"humansize",
"image", "image",
"k9", "k9",
"lazy_static", "lazy_static",

View File

@ -17,6 +17,7 @@ use_serde = ["termwiz/use_serde"]
anyhow = "1.0" anyhow = "1.0"
bitflags = "1.3" bitflags = "1.3"
csscolorparser = "0.6" csscolorparser = "0.6"
humansize = "2.1"
miniz_oxide = "0.4" miniz_oxide = "0.4"
finl_unicode = "1.2" finl_unicode = "1.2"
hex = "0.4" hex = "0.4"

View File

@ -1,5 +1,6 @@
use crate::{Position, StableRowIndex, TerminalState}; use crate::{Position, StableRowIndex, TerminalState};
use anyhow::Context; use anyhow::Context;
use humansize::{SizeFormatter, DECIMAL};
use ordered_float::NotNan; use ordered_float::NotNan;
use std::sync::Arc; use std::sync::Arc;
use termwiz::cell::Cell; use termwiz::cell::Cell;
@ -244,11 +245,12 @@ pub(crate) fn check_image_dimensions(width: u32, height: u32) -> anyhow::Result<
let size = width.saturating_mul(height).saturating_mul(4); let size = width.saturating_mul(height).saturating_mul(4);
if size > MAX_IMAGE_SIZE { if size > MAX_IMAGE_SIZE {
anyhow::bail!( anyhow::bail!(
"Ignoring image data {}x{} because {} bytes > max allowed {}", "Ignoring image data for image with dimensions {}x{} \
because required RAM {} > max allowed {}",
width, width,
height, height,
size, SizeFormatter::new(size, DECIMAL),
MAX_IMAGE_SIZE SizeFormatter::new(MAX_IMAGE_SIZE, DECIMAL),
); );
} }
Ok(()) Ok(())