Skip to content

Commit

Permalink
Now using newline as line separator in all cases (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caesarovich authored Dec 20, 2022
1 parent e343d6f commit a94569b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 11 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ const boxContent = (content, contentWidth, options) => {
const top = colorizeBorder(NEWLINE.repeat(options.margin.top) + marginLeft + chars.topLeft + (options.title ? makeTitle(options.title, chars.top.repeat(contentWidth), options.titleAlignment) : chars.top.repeat(contentWidth)) + chars.topRight);
const bottom = colorizeBorder(marginLeft + chars.bottomLeft + chars.bottom.repeat(contentWidth) + chars.bottomRight + NEWLINE.repeat(options.margin.bottom));

const LINE_SEPARATOR = (contentWidth + BORDERS_WIDTH + options.margin.left >= columns) ? '' : NEWLINE;

const lines = content.split(NEWLINE);

const middle = lines.map(line => marginLeft + colorizeBorder(chars.left) + colorizeContent(line) + colorizeBorder(chars.right)).join(LINE_SEPARATOR);
const middle = lines.map(line => marginLeft + colorizeBorder(chars.left) + colorizeContent(line) + colorizeBorder(chars.right)).join(NEWLINE);

return top + LINE_SEPARATOR + middle + LINE_SEPARATOR + bottom;
return top + NEWLINE + middle + NEWLINE + bottom;
};

const sanitizeOptions = options => {
Expand Down
20 changes: 18 additions & 2 deletions tests/snapshots/tests/float-option.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,26 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
'┌──────────────────────────────────────────────────────────┐│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob││arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo││obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar││foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob││arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo││obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar││foobarfoobar │└──────────────────────────────────────────────────────────┘'
`┌──────────────────────────────────────────────────────────┐␊
│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob│␊
│arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo│␊
│obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar│␊
│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob│␊
│arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo│␊
│obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar│␊
│foobarfoobar │␊
└──────────────────────────────────────────────────────────┘`

## float option (right) when content > columns

> Snapshot 1
'┌──────────────────────────────────────────────────────────┐│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob││arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo││obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar││foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob││arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo││obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar││foobarfoobar │└──────────────────────────────────────────────────────────┘'
`┌──────────────────────────────────────────────────────────┐␊
│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob│␊
│arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo│␊
│obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar│␊
│foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob│␊
│arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo│␊
│obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar│␊
│foobarfoobar │␊
└──────────────────────────────────────────────────────────┘`
Binary file modified tests/snapshots/tests/float-option.js.snap
Binary file not shown.
Binary file modified tests/snapshots/tests/main.js.md
Binary file not shown.
Binary file modified tests/snapshots/tests/main.js.snap
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/snapshots/tests/margin-option.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Generated by [AVA](https://avajs.dev).
`␊
┌──────────────────────────────────────────────────────────┐│axaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxax││axaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxax│└──────────────────────────────────────────────────────────┘␊
┌──────────────────────────────────────────────────────────┐␊
│axaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxax│␊
│axaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxax│␊
└──────────────────────────────────────────────────────────┘␊
`
Binary file modified tests/snapshots/tests/margin-option.js.snap
Binary file not shown.
54 changes: 50 additions & 4 deletions tests/snapshots/tests/text-align-option.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,70 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
'┌──────────────────────────────────────────────────────────┐│Lorem ipsum dolor sit amet, consectetur adipiscing elit. ││ Maecenas id erat arcu. Integer urna mauris, sodales vel ││ egestas eu, consequat id turpis. Vivamus faucibus est ││mattis tincidunt lobortis. In aliquam placerat nunc eget ││ viverra. Duis aliquet faucibus diam, blandit tincidunt ││ magna congue eu. Sed vel ante vestibulum, maximus risus ││eget, iaculis velit. Quisque id dapibus purus, ut sodales ││lorem. Aenean laoreet iaculis tellus at malesuada. Donec ││ imperdiet eu lacus vitae fringilla. │└──────────────────────────────────────────────────────────┘'
`┌──────────────────────────────────────────────────────────┐␊
│Lorem ipsum dolor sit amet, consectetur adipiscing elit. │␊
│ Maecenas id erat arcu. Integer urna mauris, sodales vel │␊
│ egestas eu, consequat id turpis. Vivamus faucibus est │␊
│mattis tincidunt lobortis. In aliquam placerat nunc eget │␊
│ viverra. Duis aliquet faucibus diam, blandit tincidunt │␊
│ magna congue eu. Sed vel ante vestibulum, maximus risus │␊
│eget, iaculis velit. Quisque id dapibus purus, ut sodales │␊
│lorem. Aenean laoreet iaculis tellus at malesuada. Donec │␊
│ imperdiet eu lacus vitae fringilla. │␊
└──────────────────────────────────────────────────────────┘`

## text alignement option (right) after wrapping

> Snapshot 1
'┌──────────────────────────────────────────────────────────┐│ Lorem ipsum dolor sit amet, consectetur adipiscing elit.││ Maecenas id erat arcu. Integer urna mauris, sodales vel││ egestas eu, consequat id turpis. Vivamus faucibus est││ mattis tincidunt lobortis. In aliquam placerat nunc eget││ viverra. Duis aliquet faucibus diam, blandit tincidunt││ magna congue eu. Sed vel ante vestibulum, maximus risus││ eget, iaculis velit. Quisque id dapibus purus, ut sodales││ lorem. Aenean laoreet iaculis tellus at malesuada. Donec││ imperdiet eu lacus vitae fringilla.│└──────────────────────────────────────────────────────────┘'
`┌──────────────────────────────────────────────────────────┐␊
│ Lorem ipsum dolor sit amet, consectetur adipiscing elit.│␊
│ Maecenas id erat arcu. Integer urna mauris, sodales vel│␊
│ egestas eu, consequat id turpis. Vivamus faucibus est│␊
│ mattis tincidunt lobortis. In aliquam placerat nunc eget│␊
│ viverra. Duis aliquet faucibus diam, blandit tincidunt│␊
│ magna congue eu. Sed vel ante vestibulum, maximus risus│␊
│ eget, iaculis velit. Quisque id dapibus purus, ut sodales│␊
│ lorem. Aenean laoreet iaculis tellus at malesuada. Donec│␊
│ imperdiet eu lacus vitae fringilla.│␊
└──────────────────────────────────────────────────────────┘`

## text alignement option (center) after wrapping + padding

> Snapshot 1
'┌──────────────────────────────────────────────────────────┐│ ││ Lorem ipsum dolor sit amet, consectetur adipiscing ││ elit. Maecenas id erat arcu. Integer urna mauris, ││ sodales vel egestas eu, consequat id turpis. Vivamus ││ faucibus est mattis tincidunt lobortis. In aliquam ││ placerat nunc eget viverra. Duis aliquet faucibus ││ diam, blandit tincidunt magna congue eu. Sed vel ││ ante vestibulum, maximus risus eget, iaculis velit. ││ Quisque id dapibus purus, ut sodales lorem. Aenean ││ laoreet iaculis tellus at malesuada. Donec imperdiet ││ eu lacus vitae fringilla. ││ │└──────────────────────────────────────────────────────────┘'
`┌──────────────────────────────────────────────────────────┐␊
│ │␊
│ Lorem ipsum dolor sit amet, consectetur adipiscing │␊
│ elit. Maecenas id erat arcu. Integer urna mauris, │␊
│ sodales vel egestas eu, consequat id turpis. Vivamus │␊
│ faucibus est mattis tincidunt lobortis. In aliquam │␊
│ placerat nunc eget viverra. Duis aliquet faucibus │␊
│ diam, blandit tincidunt magna congue eu. Sed vel │␊
│ ante vestibulum, maximus risus eget, iaculis velit. │␊
│ Quisque id dapibus purus, ut sodales lorem. Aenean │␊
│ laoreet iaculis tellus at malesuada. Donec imperdiet │␊
│ eu lacus vitae fringilla. │␊
│ │␊
└──────────────────────────────────────────────────────────┘`

## text alignement option (right) after wrapping + padding + margin

> Snapshot 1
`␊
┌──────────────────────────────────────────────────────────┐│ ││ Lorem ipsum dolor sit amet, consectetur adipiscing ││ elit. Maecenas id erat arcu. Integer urna mauris, ││ sodales vel egestas eu, consequat id turpis. Vivamus ││ faucibus est mattis tincidunt lobortis. In aliquam ││ placerat nunc eget viverra. Duis aliquet faucibus ││ diam, blandit tincidunt magna congue eu. Sed vel ││ ante vestibulum, maximus risus eget, iaculis velit. ││ Quisque id dapibus purus, ut sodales lorem. Aenean ││ laoreet iaculis tellus at malesuada. Donec imperdiet ││ eu lacus vitae fringilla. ││ │└──────────────────────────────────────────────────────────┘␊
┌──────────────────────────────────────────────────────────┐␊
│ │␊
│ Lorem ipsum dolor sit amet, consectetur adipiscing │␊
│ elit. Maecenas id erat arcu. Integer urna mauris, │␊
│ sodales vel egestas eu, consequat id turpis. Vivamus │␊
│ faucibus est mattis tincidunt lobortis. In aliquam │␊
│ placerat nunc eget viverra. Duis aliquet faucibus │␊
│ diam, blandit tincidunt magna congue eu. Sed vel │␊
│ ante vestibulum, maximus risus eget, iaculis velit. │␊
│ Quisque id dapibus purus, ut sodales lorem. Aenean │␊
│ laoreet iaculis tellus at malesuada. Donec imperdiet │␊
│ eu lacus vitae fringilla. │␊
│ │␊
└──────────────────────────────────────────────────────────┘␊
`
Binary file modified tests/snapshots/tests/text-align-option.js.snap
Binary file not shown.

0 comments on commit a94569b

Please sign in to comment.