Skip to content

Add dynamic padding support#190

Open
hzhongmj wants to merge 1 commit intoNukesor:mainfrom
hzhongmj:smart-padding
Open

Add dynamic padding support#190
hzhongmj wants to merge 1 commit intoNukesor:mainfrom
hzhongmj:smart-padding

Conversation

@hzhongmj
Copy link
Contributor

@hzhongmj hzhongmj commented Oct 14, 2025

When table has a whitespace as border, it can look quite cramped, especially when the cells have text with whitespaces. For example, below is a sample output of a certain table:

     Line  User  Idle     Location
-- ------- ----- -------- --------------------------------------
   1 con 0 root  07:29:04 -
   2 vty 3 root  09:12:23 10.243.214.227
   3 vty 5 root  07:09:36 10.243.214.212
*  4 vty 7 admin 00:00:00 fdfd:5c41:712d:d08e:2ce2:7eff:fea5:ae5

As you can see most of the columns (especially the second and third) are separated by just a single whitespace which makes it rather hard to read.

The idea of smart padding is to detect that two adjacent cells are only separated by one whitespace, in which case we add one more whitespace between the two columns. With smart_padding_width=1 the above table would look like:

     Line   User   Idle      Location
-- -------- ------ --------- --------------------------------------
   1 con 0  root   07:29:04  -
   2 vty 3  root   09:12:23  10.243.214.227
   3 vty 5  root   07:09:36  10.243.214.212
*  4 vty 7  admin  00:00:00  fdfd:5c41:712d:d08e:2ce2:7eff:fea5:ae5

It basically tries to make sure texts between adjacent cells have at least specified number of whitespaces (excluding the border).

Smart padding does not take effect if one of the condition is true:

  1. There is no extra space left
  2. The left column is right aligned and the right column is left aligned
  3. The vertical border is not ' '

@hzhongmj hzhongmj force-pushed the smart-padding branch 2 times, most recently from d19b11b to 0978e81 Compare October 14, 2025 16:57
@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 99.44134% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.89%. Comparing base (b807695) to head (ba992fe).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/formatting/smart_padding.rs 99.39% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #190      +/-   ##
==========================================
+ Coverage   96.60%   96.89%   +0.29%     
==========================================
  Files          16       17       +1     
  Lines        1530     1705     +175     
==========================================
+ Hits         1478     1652     +174     
- Misses         52       53       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hzhongmj hzhongmj force-pushed the smart-padding branch 11 times, most recently from 22ac3dd to a0a5a77 Compare October 15, 2025 01:43
@Nukesor
Copy link
Owner

Nukesor commented Oct 29, 2025

Heyo :)

I'll probably take a while to review this. There's a lot going on right now and I'm not sure when I find the mindset to drill into comfy-table once more ❤️

@hzhongmj hzhongmj force-pushed the smart-padding branch 5 times, most recently from 0608b9d to ecd6bbe Compare November 5, 2025 21:55
@hzhongmj hzhongmj force-pushed the smart-padding branch 2 times, most recently from 974d6cb to 350e558 Compare November 6, 2025 06:30
When table has a whitespace as border, it can look quite cramped,
especially when the cells have text with whitespaces. For example, below
is a sample output of a certain table:

     Line  User  Idle     Location
-- ------- ----- -------- --------------------------------------
   1 con 0 root  07:29:04 -
   2 vty 3 root  09:12:23 10.243.214.227
   3 vty 5 root  07:09:36 10.243.214.212
*  4 vty 7 admin 00:00:00 fdfd:5c41:712d:d08e:2ce2:7eff:fea5:ae5

As you can see most of the columns (especially the second and third) are
separated by just a single whitespace which makes it rather hard to read.

The idea of smart padding is to detect that two adjacent cells are only
separated by one whitespace, in which case we add one more whitespace
between the two columns. With smart_padding_width=1 the above table would
look like:

     Line   User   Idle      Location
-- -------- ------ --------- --------------------------------------
   1 con 0  root   07:29:04  -
   2 vty 3  root   09:12:23  10.243.214.227
   3 vty 5  root   07:09:36  10.243.214.212
*  4 vty 7  admin  00:00:00  fdfd:5c41:712d:d08e:2ce2:7eff:fea5:ae5

It basically tries to make sure texts between adjacent cells have at
least specified number of whitespaces (excluding the border).

Smart padding does not take effect if one of the condition is true:
1. There is no extra space left
2. The left column is right aligned and the right column is left aligned
3. The vertical border is not ' '
@hzhongmj
Copy link
Contributor Author

hzhongmj commented Jan 8, 2026

Hi Nukesor, is it still something you are planning to review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants