Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove newlines when truncating text #13

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ function formatTextWithMargins({
}
}

const text = cliTruncate(valueWithNoZeroWidthChars, spaceForText, {position: determineTruncatePosition(overflow)})
const text = cliTruncate(valueWithNoZeroWidthChars.replaceAll('\n', ' '), spaceForText, {
position: determineTruncatePosition(overflow),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to create a simple test for this newline replacement so we don't have a regression later.

Also, unrelated: this uncovered an issue with align-center where the first line is not centered.

Wrap (aligned center)
┌───────┬─────────┬─────┬───────────────────────────────────────────────────────────────────────────┐
│  Id   │  Name   │ Age │                                Description                                │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 36329 │  Alice  │ 20  │  Lorem ipsum dolor sit amet, consectetur                                  │
│       │         │     │                                   adipi                                   │
│       │         │     │  scing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna   │
│       │         │     │                                  aliqua.                                  │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 49032 │   Bob   │ 21  │  Lorem ipsum dolor sit amet, consectetur                                  │
│       │         │     │                                   adipi                                   │
│       │         │     │  scing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna   │
│       │         │     │                                  aliqua.                                  │
├───────┼─────────┼─────┼───────────────────────────────────────────────────────────────────────────┤
│ 51786 │ Charlie │ 22  │  Lorem ipsum dolor sit amet, consectetur                                  │
│       │         │     │                                   adipi                                   │
│       │         │     │  scing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna   │
│       │         │     │                                  aliqua.                                  │
└───────┴─────────┴─────┴───────────────────────────────────────────────────────────────────────────┘

const spaces = width - stripAnsi(text).length
return {
text,
Expand Down