sdj3261 opened a new pull request, #7719:
URL: https://github.com/apache/gravitino/pull/7719
[#7685] fix(cli): use display width to align table output for multibyte
characters
---
## What changes were proposed in this pull request?
- Replace `String.length()` checks with `LineUtil.getDisplayWidth()` to
correctly calculate character width for multibyte characters.
---
## Why are the changes needed?
Currently, table output in the CLI uses `String.length()` to calculate cell
width. This causes misalignment when rendering multibyte characters such as
Korean, Japanese, or Chinese characters.
Fixes: #7685
---
## Does this PR introduce _any_ user-facing change?
- Yes, Tables displayed in the CLI will now correctly align columns when
using multibyte characters.
## How was this patch tested?
- Not committed yet, but tested locally with unit tests.
```java
@Test
void testMultiByteCharacterTableFormat() {
CommandContext mockContext = TestCliUtil.getMockContext();
Column columnA = new Column(mockContext, "이름",
Column.HorizontalAlign.LEFT, Column.HorizontalAlign.LEFT);
Column columnB = new Column(mockContext, "설명",
Column.HorizontalAlign.LEFT, Column.HorizontalAlign.LEFT);
TableFormat<String> tableFormat =
new TableFormat<String>(mockContext) {
@Override
public String getOutput(String entity) {
return null;
}
};
String eol = System.lineSeparator();
String expected =
"+--------+--------------+" + eol
+ "| 이름 | 설명 |" + eol
+ "+--------+--------------+" + eol
+ "| 홍길동 | 테스트입니다 |" + eol
+ "| 김철수 | 멀티바이트 |" + eol
+ "| 이영희 | 길이체크 |" + eol
+ "+--------+--------------+";
String outputString = tableFormat.getTableFormat(columnA, columnB).trim();
Assertions.assertEquals(expected, outputString);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]