xorcist 0.1.0

A TUI client for jj (Jujutsu VCS)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
//! UI rendering with ratatui.

use ansi_to_tui::IntoText;
use ratatui::{
    Frame,
    layout::{Constraint, Flex, Layout, Position, Rect},
    style::{Color, Modifier, Style, Stylize},
    text::{Line, Span, Text},
    widgets::{Block, Borders, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
};

use crate::app::{App, InputMode, ModalState, View};
use crate::jj::{DiffStatus, ShowOutput};

/// Render the entire UI based on current view.
pub fn render(frame: &mut Frame, app: &mut App) {
    match app.view {
        View::Log => render_log_view(frame, app),
        View::Detail => render_detail_view(frame, app),
    }

    // Render input overlay if in input mode
    if app.is_input_mode() {
        render_input_overlay(frame, app);
    }

    // Render help modal on top if visible
    if app.show_help {
        render_help(frame);
    }

    // Render modal dialog if open
    if app.is_modal_open() {
        render_modal_overlay(frame, app);
    }
}

/// Render the log view.
fn render_log_view(frame: &mut Frame, app: &mut App) {
    let chunks = Layout::vertical([
        Constraint::Length(1), // Title bar
        Constraint::Min(3),    // Log list
        Constraint::Length(1), // Status bar
    ])
    .split(frame.area());

    render_title_bar(frame, chunks[0], app);
    render_log_list(frame, chunks[1], app);
    render_log_status_bar(frame, chunks[2], app);
}

/// Render the title bar.
fn render_title_bar(frame: &mut Frame, area: Rect, app: &App) {
    let title = format!(" xorcist - {} ", app.repo_root);
    let title_bar = Paragraph::new(title).style(Style::default().bg(Color::Blue).fg(Color::White));
    frame.render_widget(title_bar, area);
}

/// Render the log list with ANSI graph output.
fn render_log_list(frame: &mut Frame, area: Rect, app: &mut App) {
    let viewport_height = area.height as usize;

    // Ensure selected line is visible
    app.ensure_selected_visible(viewport_height);

    // Get the selected line index for highlighting
    let selected_line_idx = app.selected_line_index();

    // Build text from graph lines
    let mut lines: Vec<Line> = Vec::new();

    for (idx, graph_line) in app.graph_log.lines.iter().enumerate() {
        // Parse ANSI codes to ratatui Line
        let text = graph_line
            .raw
            .as_bytes()
            .into_text()
            .unwrap_or_else(|_| Text::raw(&graph_line.raw));

        // Get the first line (should only be one line per graph_line)
        let mut line = if text.lines.is_empty() {
            Line::raw("")
        } else {
            text.lines.into_iter().next().unwrap()
        };

        // Transform description for commit lines
        if let Some(ref desc) = graph_line.description {
            line = transform_line_description(line, &graph_line.plain, desc);
        }

        // Highlight selected line
        if Some(idx) == selected_line_idx {
            // Apply background color to indicate selection
            line = line.bg(Color::Indexed(236)).bold();
        }

        lines.push(line);
    }

    let paragraph = Paragraph::new(lines).scroll((app.scroll_offset as u16, 0));
    frame.render_widget(paragraph, area);

    // Scrollbar
    let total_lines = app.line_count();
    if total_lines > viewport_height {
        let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
            .begin_symbol(Some(""))
            .end_symbol(Some(""));
        let mut scrollbar_state = ScrollbarState::new(total_lines.saturating_sub(viewport_height))
            .position(app.scroll_offset);
        frame.render_stateful_widget(scrollbar, area, &mut scrollbar_state);
    }
}

/// Transform a line's description part.
///
/// - Empty description: replace with "(no desc)" in DarkGray italic
/// - Conventional commits: convert to emoji format
fn transform_line_description<'a>(line: Line<'a>, plain: &str, description: &str) -> Line<'a> {
    // Handle empty description: keep all original spans and append "(no desc)"
    if description.is_empty() {
        let mut spans: Vec<Span<'a>> = line.spans.into_iter().collect();
        // Prevent selection highlight from filling this separator space.
        // (Spans with explicit bg=Reset override the line background.)
        spans.push(Span::styled(" ", Style::default().bg(Color::Reset)));
        spans.push(Span::styled(
            "(no desc)",
            Style::default().fg(Color::DarkGray).italic(),
        ));
        return Line::from(spans);
    }

    // Find the position of description in the plain text
    let desc_start = match plain.find(description) {
        Some(pos) => pos,
        None => return line, // Description not found, return unchanged
    };

    // Calculate prefix (everything before description)
    let prefix_plain = &plain[..desc_start];

    // Find how many characters to keep from the original spans
    let mut prefix_char_count = 0;
    let mut prefix_spans: Vec<Span<'a>> = Vec::new();

    for span in line.spans.into_iter() {
        let span_len = span.content.chars().count();
        let prefix_remaining = prefix_plain
            .chars()
            .count()
            .saturating_sub(prefix_char_count);

        if prefix_remaining == 0 {
            // We've collected all prefix spans, skip the rest (description part)
            break;
        } else if span_len <= prefix_remaining {
            // This entire span is part of the prefix
            prefix_char_count += span_len;
            prefix_spans.push(span);
        } else {
            // This span partially overlaps - split it
            let chars: String = span.content.chars().take(prefix_remaining).collect();
            prefix_spans.push(Span::styled(chars, span.style));
            break;
        }
    }

    // Apply conventional commits emoji transformation
    let transformed = crate::conventional::format_commit_message(description);
    if transformed != description {
        // Conventional commit was transformed - use default style for emoji text
        prefix_spans.push(Span::raw(transformed));
    } else {
        // Not a conventional commit - keep original style (just use raw text)
        prefix_spans.push(Span::raw(description.to_string()));
    }

    Line::from(prefix_spans)
}

/// Render the status bar for log view.
fn render_log_status_bar(frame: &mut Frame, area: Rect, app: &App) {
    // Show command result if available, otherwise show help text
    let (text, style) = if app.is_loading_more {
        (
            " Loading more entries... ".to_string(),
            Style::default().bg(Color::DarkGray).fg(Color::Yellow),
        )
    } else if let Some(result) = &app.last_command_result {
        let color = if result.success {
            Color::Green
        } else {
            Color::Red
        };
        let prefix = if result.success { "" } else { "" };
        let msg = format!(
            " {prefix} {} ",
            truncate_message(&result.message, area.width as usize - 4)
        );
        (msg, Style::default().bg(Color::DarkGray).fg(color))
    } else {
        // Build help text with entry count info
        let count_info = if app.has_more_entries {
            format!("[{}+ commits] ", app.commit_count())
        } else {
            format!("[{} commits] ", app.commit_count())
        };
        let help = format!(
            " {count_info}n: new  e: edit  d: describe  b: bookmark  Enter: show  q: quit  ?: help "
        );
        (help, Style::default().bg(Color::DarkGray).fg(Color::White))
    };

    let status_bar = Paragraph::new(text).style(style);
    frame.render_widget(status_bar, area);
}

/// Truncate a message (first line only) to fit within the given display width.
fn truncate_message(msg: &str, max_width: usize) -> String {
    let first_line = msg.lines().next().unwrap_or(msg);
    crate::text::truncate_str(first_line, max_width)
}

/// Render the detail view.
fn render_detail_view(frame: &mut Frame, app: &mut App) {
    let Some(state) = &app.detail_state else {
        return;
    };

    let chunks = Layout::vertical([
        Constraint::Length(1), // Title bar
        Constraint::Min(3),    // Content
        Constraint::Length(1), // Status bar
    ])
    .split(frame.area());

    // Title bar
    let change_id_short = &state.show_output.change_id[..8.min(state.show_output.change_id.len())];
    let title = format!(" Revision: {change_id_short} ");
    let title_bar =
        Paragraph::new(title).style(Style::default().bg(Color::Magenta).fg(Color::White));
    frame.render_widget(title_bar, chunks[0]);

    // Content area
    let content_area = chunks[1];
    render_detail_content(frame, content_area, app);

    // Status bar
    render_detail_status_bar(frame, chunks[2]);
}

/// Render the detail content with scrolling.
fn render_detail_content(frame: &mut Frame, area: Rect, app: &mut App) {
    let Some(state) = &app.detail_state else {
        return;
    };

    // Build content lines
    let lines = build_detail_lines(&state.show_output);
    let content_height = lines.len();

    // Update content height in app state
    app.set_detail_content_height(content_height);

    // Get current scroll position (re-borrow after mutation)
    let scroll = app.detail_state.as_ref().map(|s| s.scroll).unwrap_or(0);

    let visible_height = area.height as usize;
    let max_scroll = content_height.saturating_sub(visible_height);
    let clamped_scroll = scroll.min(max_scroll);

    let paragraph = Paragraph::new(lines)
        .scroll((clamped_scroll as u16, 0))
        .block(Block::default().borders(Borders::LEFT | Borders::RIGHT));
    frame.render_widget(paragraph, area);

    // Scrollbar
    if content_height > visible_height {
        let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
            .begin_symbol(Some(""))
            .end_symbol(Some(""));
        let mut scrollbar_state =
            ScrollbarState::new(content_height.saturating_sub(visible_height))
                .position(clamped_scroll);
        frame.render_stateful_widget(scrollbar, area, &mut scrollbar_state);
    }
}

fn styled_id_line(label: &'static str, prefix: &str, rest: &str, color: Color) -> Line<'static> {
    Line::from(vec![
        Span::styled(label, Style::default().bold()),
        Span::styled(
            prefix.to_string(),
            Style::default().fg(color).add_modifier(Modifier::BOLD),
        ),
        Span::styled(rest.to_string(), Style::default().fg(Color::DarkGray)),
    ])
}

/// Build lines for detail view content.
fn build_detail_lines(output: &ShowOutput) -> Vec<Line<'static>> {
    let mut lines = vec![
        styled_id_line(
            "Change ID: ",
            &output.change_id_prefix,
            &output.change_id_rest,
            Color::Magenta,
        ),
        styled_id_line(
            "Commit ID: ",
            &output.commit_id_prefix,
            &output.commit_id_rest,
            Color::Yellow,
        ),
        Line::from(vec![
            Span::styled("Author:    ", Style::default().bold()),
            Span::styled(output.author.clone(), Style::default().fg(Color::Cyan)),
        ]),
        Line::from(vec![
            Span::styled("Date:      ", Style::default().bold()),
            Span::raw(output.timestamp.clone()),
        ]),
    ];

    if !output.bookmarks.is_empty() {
        lines.push(Line::from(vec![
            Span::styled("Bookmarks: ", Style::default().bold()),
            Span::styled(
                output.bookmarks.join(", "),
                Style::default().fg(Color::Cyan),
            ),
        ]));
    }

    lines.push(Line::raw(""));

    // Description (first line gets emoji conversion)
    lines.push(Line::styled(
        "─── Description ───",
        Style::default().fg(Color::DarkGray),
    ));
    let mut desc_lines = output.description.lines();
    if let Some(first_line) = desc_lines.next() {
        // Apply conventional commits emoji to first line only
        let formatted = crate::conventional::format_commit_message(first_line);
        lines.push(Line::raw(formatted));
        // Remaining lines as-is
        for desc_line in desc_lines {
            lines.push(Line::raw(desc_line.to_string()));
        }
    }
    if output.description.is_empty() {
        lines.push(Line::styled(
            "(no description)",
            Style::default().fg(Color::DarkGray).italic(),
        ));
    }

    lines.push(Line::raw(""));

    // Diff summary
    lines.push(Line::styled(
        "─── Changed Files ───",
        Style::default().fg(Color::DarkGray),
    ));
    for entry in &output.diff_summary {
        let (symbol, color) = match entry.status {
            DiffStatus::Added => ("+", Color::Green),
            DiffStatus::Modified => ("~", Color::Yellow),
            DiffStatus::Deleted => ("-", Color::Red),
            DiffStatus::Renamed => ("", Color::Cyan),
            DiffStatus::Copied => ("", Color::Blue),
        };
        lines.push(Line::from(vec![
            Span::styled(format!(" {symbol} "), Style::default().fg(color).bold()),
            Span::raw(entry.path.clone()),
        ]));
    }

    if output.diff_summary.is_empty() {
        lines.push(Line::styled(
            "  (no changes)",
            Style::default().fg(Color::DarkGray).italic(),
        ));
    }

    lines
}

/// Render the status bar for detail view.
fn render_detail_status_bar(frame: &mut Frame, area: Rect) {
    let help_text = " j/k: scroll  Ctrl+d/u: page  q/Esc: back  ?: help ";
    let status_bar =
        Paragraph::new(help_text).style(Style::default().bg(Color::DarkGray).fg(Color::White));
    frame.render_widget(status_bar, area);
}

/// Render the help modal.
fn render_help(frame: &mut Frame) {
    let area = centered_rect(frame.area(), 50, 80);

    // Clear the area first to avoid background bleed-through
    frame.render_widget(Clear, area);

    let help_lines = vec![
        Line::styled(
            "─── Keyboard Shortcuts ───",
            Style::default().fg(Color::Cyan).bold(),
        ),
        Line::raw(""),
        Line::styled("  Navigation", Style::default().bold()),
        Line::from(vec![
            Span::styled("  j / ↓      ", Style::default().fg(Color::Yellow)),
            Span::raw("Move down"),
        ]),
        Line::from(vec![
            Span::styled("  k / ↑      ", Style::default().fg(Color::Yellow)),
            Span::raw("Move up"),
        ]),
        Line::from(vec![
            Span::styled("  g / Home   ", Style::default().fg(Color::Yellow)),
            Span::raw("Go to top"),
        ]),
        Line::from(vec![
            Span::styled("  G / End    ", Style::default().fg(Color::Yellow)),
            Span::raw("Go to bottom"),
        ]),
        Line::from(vec![
            Span::styled("  Ctrl+d     ", Style::default().fg(Color::Yellow)),
            Span::raw("Page down"),
        ]),
        Line::from(vec![
            Span::styled("  Ctrl+u     ", Style::default().fg(Color::Yellow)),
            Span::raw("Page up"),
        ]),
        Line::raw(""),
        Line::styled("  jj Commands", Style::default().bold()),
        Line::from(vec![
            Span::styled("  n          ", Style::default().fg(Color::Yellow)),
            Span::raw("New change"),
        ]),
        Line::from(vec![
            Span::styled("  N          ", Style::default().fg(Color::Yellow)),
            Span::raw("New change with message"),
        ]),
        Line::from(vec![
            Span::styled("  e          ", Style::default().fg(Color::Yellow)),
            Span::raw("Edit revision"),
        ]),
        Line::from(vec![
            Span::styled("  d          ", Style::default().fg(Color::Yellow)),
            Span::raw("Describe revision"),
        ]),
        Line::from(vec![
            Span::styled("  b          ", Style::default().fg(Color::Yellow)),
            Span::raw("Set bookmark"),
        ]),
        Line::from(vec![
            Span::styled("  a          ", Style::default().fg(Color::Yellow)),
            Span::raw("Abandon revision"),
        ]),
        Line::from(vec![
            Span::styled("  s          ", Style::default().fg(Color::Yellow)),
            Span::raw("Squash into parent"),
        ]),
        Line::from(vec![
            Span::styled("  f          ", Style::default().fg(Color::Yellow)),
            Span::raw("Git fetch"),
        ]),
        Line::from(vec![
            Span::styled("  p          ", Style::default().fg(Color::Yellow)),
            Span::raw("Git push"),
        ]),
        Line::from(vec![
            Span::styled("  u          ", Style::default().fg(Color::Yellow)),
            Span::raw("Undo last operation"),
        ]),
        Line::raw(""),
        Line::styled("  General", Style::default().bold()),
        Line::from(vec![
            Span::styled("  Enter      ", Style::default().fg(Color::Yellow)),
            Span::raw("Open detail view"),
        ]),
        Line::from(vec![
            Span::styled("  q          ", Style::default().fg(Color::Yellow)),
            Span::raw("Quit / Close view"),
        ]),
        Line::from(vec![
            Span::styled("  Esc        ", Style::default().fg(Color::Yellow)),
            Span::raw("Close detail / help"),
        ]),
        Line::from(vec![
            Span::styled("  ?          ", Style::default().fg(Color::Yellow)),
            Span::raw("Toggle this help"),
        ]),
    ];

    let help_widget = Paragraph::new(help_lines).block(
        Block::default()
            .borders(Borders::ALL)
            .border_style(Style::default().fg(Color::Cyan))
            .title(" Help "),
    );

    frame.render_widget(help_widget, area);
}

/// Calculate a centered rectangle with given percentage of width and height.
fn centered_rect(area: Rect, percent_x: u16, percent_y: u16) -> Rect {
    let vertical = Layout::vertical([Constraint::Percentage(percent_y)]).flex(Flex::Center);
    let horizontal = Layout::horizontal([Constraint::Percentage(percent_x)]).flex(Flex::Center);
    let [area] = vertical.areas(area);
    let [area] = horizontal.areas(area);
    area
}

/// Render the modal overlay for confirmation dialogs.
fn render_modal_overlay(frame: &mut Frame, app: &App) {
    let ModalState::Confirm(action) = &app.modal else {
        return;
    };

    let message = action.confirm_message();

    // Calculate centered area for modal box
    let area = frame.area();
    let width = (message.len() as u16 + 6).max(30).min(area.width - 4);
    let height = 5;
    let x = (area.width.saturating_sub(width)) / 2;
    let y = (area.height.saturating_sub(height)) / 2;
    let modal_area = Rect::new(x, y, width, height);

    // Clear the area behind the modal box
    frame.render_widget(Clear, modal_area);

    // Build the modal box
    let block = Block::default()
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Yellow))
        .title(" Confirm ")
        .title_style(Style::default().fg(Color::Yellow).bold());

    let inner_area = block.inner(modal_area);
    frame.render_widget(block, modal_area);

    // Split inner area for message and buttons
    let chunks = Layout::vertical([
        Constraint::Length(1), // Message
        Constraint::Length(1), // Spacing
        Constraint::Length(1), // Buttons
    ])
    .split(inner_area);

    // Render message (centered)
    let message_paragraph = Paragraph::new(message).alignment(ratatui::layout::Alignment::Center);
    frame.render_widget(message_paragraph, chunks[0]);

    // Render buttons
    let buttons = Line::from(vec![
        Span::styled(" [Y]es ", Style::default().fg(Color::Green).bold()),
        Span::raw("  "),
        Span::styled(" [N]o ", Style::default().fg(Color::Red).bold()),
    ]);
    let buttons_paragraph = Paragraph::new(buttons).alignment(ratatui::layout::Alignment::Center);
    frame.render_widget(buttons_paragraph, chunks[2]);
}

/// Render the input overlay for text entry.
fn render_input_overlay(frame: &mut Frame, app: &App) {
    let Some(mode) = &app.input_mode else {
        return;
    };

    // Calculate centered area for input box
    let area = frame.area();
    let width = (area.width * 60 / 100).max(40).min(area.width - 4);
    let height = 3;
    let x = (area.width.saturating_sub(width)) / 2;
    let y = (area.height.saturating_sub(height)) / 2;
    let input_area = Rect::new(x, y, width, height);

    // Clear the area behind the input box
    frame.render_widget(Clear, input_area);

    // Build the input box
    let title = match mode {
        InputMode::Describe => " Describe ",
        InputMode::BookmarkSet => " Set Bookmark ",
        InputMode::NewWithMessage => " New Change ",
    };

    let block = Block::default()
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Cyan))
        .title(title)
        .title_style(Style::default().fg(Color::Cyan).bold());

    let inner_area = block.inner(input_area);
    frame.render_widget(block, input_area);

    // Render the input text
    let input_value = app.input.value();
    let display_text = if input_value.is_empty() {
        Span::styled(mode.placeholder(), Style::default().fg(Color::DarkGray))
    } else {
        Span::raw(input_value)
    };

    // Calculate scroll for long input
    let scroll = app.input.visual_scroll(inner_area.width as usize);
    let input_paragraph = Paragraph::new(Line::from(display_text)).scroll((0, scroll as u16));
    frame.render_widget(input_paragraph, inner_area);

    // Set cursor position
    if !input_value.is_empty() || app.is_input_mode() {
        let cursor_x = app.input.visual_cursor().saturating_sub(scroll);
        frame.set_cursor_position(Position::new(inner_area.x + cursor_x as u16, inner_area.y));
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_truncate_message_ascii() {
        assert_eq!(truncate_message("hello world", 8), "hello...");
        assert_eq!(truncate_message("short", 10), "short");
    }

    #[test]
    fn test_truncate_message_japanese() {
        // Japanese characters: 1 char = 2 width
        assert_eq!(truncate_message("日本語", 10), "日本語"); // 6 width
        assert_eq!(truncate_message("日本語テスト", 10), "日本語..."); // 12 width -> truncate
    }

    #[test]
    fn test_truncate_message_multiline() {
        // Should only use the first line
        assert_eq!(truncate_message("first\nsecond", 20), "first");
        assert_eq!(truncate_message("日本語\n英語", 20), "日本語");
    }

    #[test]
    fn test_truncate_message_mixed() {
        assert_eq!(truncate_message("Hello世界", 10), "Hello世界"); // 5 + 4 = 9 width
        // "Error: 失敗しました" = 7 + 10 = 17 width, truncate to 15 → "Error: 失敗..." (7 + 4 + 3 = 14)
        assert_eq!(
            truncate_message("Error: 失敗しました", 15),
            "Error: 失敗..."
        );
    }
}