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(
176 } 176 }
177 let mut placeholder = "\u{230c}".to_string(); 177 let mut placeholder = "\u{230c}".to_string();
178 placeholder.push_str(&" ".repeat(width - 2)); 178 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
180 if *height > 2 { 182 if *height > 2 {
181 if let Some(text) = text { 183 if let Some(text) = text {
182 if text.width() <= width - 2 { 184 if text.width() <= width - 2 {
@@ -186,7 +188,7 @@ fn placeholder_frame(
186 } 188 }
187 } 189 }
188 190
189 placeholder.push_str(&"\n".repeat(height - 2)); 191 placeholder.push_str(&"\n".repeat(height / 2));
190 placeholder.push('\u{230e}'); 192 placeholder.push('\u{230e}');
191 placeholder.push_str(&" ".repeat(width - 2)); 193 placeholder.push_str(&" ".repeat(width - 2));
192 placeholder.push_str("\u{230f}\n"); 194 placeholder.push_str("\u{230f}\n");
@@ -1087,7 +1089,7 @@ impl Message {
1087 }, 1089 },
1088 ImageStatus::Loaded(backend) => { 1090 ImageStatus::Loaded(backend) => {
1089 proto = Some(backend); 1091 proto = Some(backend);
1090 placeholder_frame(Some("Loading..."), width, &backend.area().into()) 1092 placeholder_frame(Some("Cut off..."), width, &backend.area().into())
1091 }, 1093 },
1092 ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")), 1094 ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")),
1093 }; 1095 };
@@ -1358,6 +1360,33 @@ pub mod tests {
1358 OK 1360 OK
1359 1361
1360⌎ ⌏ 1362⌎ ⌏
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⌎ ⌏
1361"# 1390"#
1362 ) 1391 )
1363 ); 1392 );