Update tuzuru list command with swift-wcwidth#18
Conversation
There was a problem hiding this comment.
Pull Request Overview
Updates the tuzuru list command from CSV output to a formatted table with proper Unicode character width handling using the swift-wcwidth library.
- Replaces CSV output with a bordered table format
- Adds Year and Category columns to display additional metadata
- Implements proper Unicode character width calculation for accurate column alignment
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Sources/Command/ListCommand.swift | Transforms CSV output to table format with new columns and Unicode-aware text handling |
| Package.swift | Adds swift-wcwidth dependency for proper character width calculation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if wcwidth(string) <= maxLength { | ||
| return string | ||
| } | ||
| return String(string.prefix(maxLength - 3)) + "..." | ||
|
|
||
| var truncated = "" | ||
| var currentWidth = 0 | ||
| let ellipsis = "..." | ||
| let ellipsisWidth = wcwidth(ellipsis) | ||
| let targetWidth = maxLength - ellipsisWidth | ||
|
|
||
| for char in string { | ||
| let charWidth = wcwidth(char) |
There was a problem hiding this comment.
The wcwidth function should be called on the wcwidth instance, not as a standalone function. Use wcwidth.width(of: string) instead of wcwidth(string).
67979d6 to
02b8496
Compare
Previously,
tuzuru listcommand was implemented with compromised solution outputting data in CSV format, which works fine for debug purpose. But I'd love to put those data in a table with border to make it readable.I needed to investigate how to do it and learn
wcwidth,ICU, Unicode's EastAsianWidth.txt, or some equivalent OSS in other languages. As a result, I created https://github.com/ainame/swift-wcwidth based on my research.tuzuru listnow use it internally and can draw perfect table even when CJK chars, Thai, Arabic, or emojis appear in the output.