Skip to content

feat: Create formatter module for Claude Code-style output #195

@mkusaka

Description

@mkusaka

Overview

This issue is part of implementing Claude Code-style formatting (#171). We need to create a formatter module that handles different display formats (List, Preview, Detail) according to Claude Code's visual style.

Requirements

Formatter Types

  1. List Formatter

    • Single-line display with newlines replaced by spaces
    • Tool executions as ToolName(args)
    • Long arguments truncated with
    • Example: Bash(git commit -m "feat: enhance...")
  2. Preview Formatter

    • Multi-line with Claude Code markers
    • First few lines followed by … +XX lines (ctrl+r to expand)
    • Format:
      ⏺ ToolName(arguments)
        ⎿ Result content
           More content
           … +XX lines (ctrl+r to expand)
      
  3. Detail Formatter

    • Complete content without truncation
    • All markers and formatting preserved
    • No … +XX lines truncation

Implementation Details

Create new file: src/output/formatter.rs

use crate::schemas::tool_parser::{ParsedMessage, ToolExecution};

pub enum DisplayFormat {
    List,
    Preview { max_lines: usize },
    Detail,
}

pub struct ClaudeCodeFormatter {
    format: DisplayFormat,
}

impl ClaudeCodeFormatter {
    pub fn new(format: DisplayFormat) -> Self { }
    
    pub fn format_message(&self, parsed: &ParsedMessage) -> String { }
    
    pub fn format_tool_execution(&self, tool: &ToolExecution) -> String { }
    
    pub fn format_thinking_block(&self, content: &str) -> String { }
}

// Utility functions
pub fn truncate_with_ellipsis(text: &str, max_len: usize) -> String { }
pub fn format_line_count(count: usize) -> String { }
pub fn indent_content(content: &str, level: usize) -> String { }

Special Characters

  • (U+23FA) - Record button for actions
  • (U+23BF) - Circuit ground for results
  • (U+273B) - Teardrop-spoked asterisk for thinking
  • (U+2026) - Horizontal ellipsis for truncation

Formatting Rules

  1. Indentation: 2 spaces after
  2. Line truncation:
    • List view: ~100 chars max
    • Preview: configurable (default 5 lines)
  3. Argument truncation: Show first part + ... for long arguments

Testing

  • Unit tests for each formatter type
  • Tests for special character handling
  • Tests for multi-byte character safety (Japanese, emojis)
  • Edge cases (empty content, very long lines)

Acceptance Criteria

  • List formatter produces single-line output
  • Preview formatter shows truncated multi-line output
  • Detail formatter preserves complete content
  • Special Claude Code markers render correctly
  • Handles multi-byte characters safely
  • All tests pass
  • Documentation with examples

Dependencies

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions