ayonious / console-table-printer

πŸ–₯️ 🍭 Printing Pretty Tables on your console
https://console-table.netlify.app
MIT License
172 stars 22 forks source link

fix: add character length dictionary for string length computation in console #431

Closed mkah91 closed 2 years ago

mkah91 commented 2 years ago

πŸ‘€What is this pr about?

The PR introduces an optional charLength dictionary in the findWidthInConsole method that is used to compute the length of a string in console. With that dictionary you can assign a certain length to a character or a string.

πŸš€ Changes

Fixed

https://github.com/ayonious/console-table-printer/issues/389 https://github.com/ayonious/console-table-printer/issues/430

πŸ–Ό Screenshots

const bundle = new Table({
  title: 'Bundle (BUNDLENAME)',
  columns: [
    { name: 'Weapon' },
    { name: 'Chroma' },
    { name: 'Quality' },
    { name: 'Price' },
  ],
+ charLength: { 'πŸ‘': 2, 'βœ…': 2 },
})

bundle.addRows([
  {
    Weapon: 'πŸ‘',
    Chroma: 'βœ…',
    Quality: 'Deluxe',
    Price: '1 775 VP',
  },
])

bundle.printTable()
Before After
image image
ayonious commented 2 years ago

LGTM

ayonious commented 2 years ago

Thanks a lot @mkah91

ayonious commented 2 years ago

:tada: This PR is included in version 2.11.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

markg85 commented 2 years ago

This is such a cool fix! Really makes tables smile back, hehehe