Skip to content

Commit 59b5561

Browse files
committed
fix(bench): correct header box alignment with unicode-aware width calculation
Fixed the alignment offset in print_header() function: - Changed padding calculation from (110 - text.len()) to (107 - text_width) - Added unicode_width dependency for proper emoji display width handling - Now correctly handles headers with emojis like "📊 SUMMARY" The box structure is: - Total width: 110 chars - Border + space: ║ (2 chars) - Text content: text_width chars - Padding: (107 - text_width) chars - Final border: ║ (1 char)
1 parent 53ef5f0 commit 59b5561

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ crossterm = "0.28"
2828
serde = { version = "1.0", features = ["derive"] }
2929
serde_json = "1.0"
3030
comfy-table = "7.1"
31+
unicode-width = "0.2"
3132

3233
[build-dependencies]
3334
clap = { version = "4.5.39", features = ["derive", "cargo"] }

src/bin/bench_throughput.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use serde::{Serialize, Serializer};
1212
use std::io::{self, Write};
1313
use std::time::{Duration, Instant};
1414
use string_pipeline::Template;
15+
use unicode_width::UnicodeWidthStr;
1516

1617
// Helper to serialize Duration as nanoseconds
1718
fn serialize_duration<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
@@ -392,6 +393,7 @@ fn format_size(size: usize) -> String {
392393
// Styled output helpers
393394
fn print_header(text: &str) {
394395
let mut stdout = io::stdout();
396+
let text_width = text.width();
395397
let _ = execute!(
396398
stdout,
397399
SetForegroundColor(Color::Cyan),
@@ -400,7 +402,7 @@ fn print_header(text: &str) {
400402
Print("═".repeat(108)),
401403
Print("╗\n║ "),
402404
Print(text),
403-
Print(" ".repeat(110 - text.len())),
405+
Print(" ".repeat(107 - text_width)),
404406
Print("║\n╚"),
405407
Print("═".repeat(108)),
406408
Print("╝\n"),

0 commit comments

Comments
 (0)