Commit fed19d7a4b

fed19d7a4becd8923d4082b905cd70f08fc9dce8

parent: ed9ee26854

Unregistered key

VAWVAW <git@nlih.de> · 2025-06-21 18:25 UTC
committer: <noreply@github.com>

Improve image preview placeholder (#453)

Layout: unified · split

src/message/mod.rs +32 −3
@@ -176,7 +176,9 @@ fn placeholder_frame(
176176 }
177177 let mut placeholder = "\u{230c}".to_string();
178178 placeholder.push_str(&" ".repeat(width - 2));
179 placeholder.push_str("\u{230d}\n");
179 placeholder.push('\u{230d}');
180 placeholder.push_str(&"\n".repeat((height - 1) / 2));
181
180182 if *height > 2 {
181183 if let Some(text) = text {
182184 if text.width() <= width - 2 {
@@ -186,7 +188,7 @@ fn placeholder_frame(
186188 }
187189 }
188190
189 placeholder.push_str(&"\n".repeat(height - 2));
191 placeholder.push_str(&"\n".repeat(height / 2));
190192 placeholder.push('\u{230e}');
191193 placeholder.push_str(&" ".repeat(width - 2));
192194 placeholder.push_str("\u{230f}\n");
@@ -1087,7 +1089,7 @@ impl Message {
10871089 },
10881090 ImageStatus::Loaded(backend) => {
10891091 proto = Some(backend);
1090 placeholder_frame(Some("Loading..."), width, &backend.area().into())
1092 placeholder_frame(Some("Cut off..."), width, &backend.area().into())
10911093 },
10921094 ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")),
10931095 };
@@ -1358,6 +1360,33 @@ pub mod tests {
13581360 OK
13591361
13601362⌎ ⌏
1363"#
1364 )
1365 );
1366 assert_eq!(
1367 placeholder_frame(Some("OK"), 6, &ImagePreviewSize { width: 6, height: 6 }),
1368 pretty_frame_test(
1369 r#"
1370⌌ ⌍
1371
1372 OK
1373
1374
1375⌎ ⌏
1376"#
1377 )
1378 );
1379 assert_eq!(
1380 placeholder_frame(Some("OK"), 6, &ImagePreviewSize { width: 6, height: 7 }),
1381 pretty_frame_test(
1382 r#"
1383⌌ ⌍
1384
1385
1386 OK
1387
1388
1389⌎ ⌏
13611390"#
13621391 )
13631392 );