Skip to content

Commit

Permalink
fix: calculate width of wrapped ansi
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 24, 2024
1 parent f2379df commit 796359e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function determineTruncatePosition(overflow: Overflow): 'start' | 'middle' | 'en
}
}

function doStuffWithText({
function formatTextWithMargins({
horizontalAlignment,
overflow,
padding,
Expand Down Expand Up @@ -138,8 +138,7 @@ function doStuffWithText({

if (overflow === 'wrap') {
const wrappedText = wrapAnsi(valueWithNoZeroWidthChars, spaceForText, {hard: true, trim: true, wordWrap: true})
const {marginLeft, marginRight} = calculateMargins(width - determineWidthOfWrappedText(wrappedText))

const {marginLeft, marginRight} = calculateMargins(width - determineWidthOfWrappedText(stripAnsi(wrappedText)))
const text = wrappedText.replaceAll('\n', `${' '.repeat(marginRight)}\n${' '.repeat(marginLeft)}`)

return {
Expand Down Expand Up @@ -326,7 +325,7 @@ function row<T extends Record<string, unknown>>(config: RowConfig): (props: RowP
}

const key = `${props.key}-cell-${column.key}`
const {marginLeft, marginRight, text} = doStuffWithText({
const {marginLeft, marginRight, text} = formatTextWithMargins({
horizontalAlignment,
overflow,
padding,
Expand Down

0 comments on commit 796359e

Please sign in to comment.