presenterm icon indicating copy to clipboard operation
presenterm copied to clipboard

Text isn't centred

Open 0atman opened this issue 9 months ago • 9 comments

Here's a good example from something I'm working on:

Image

The left margin, 1, is wider than the right. It's offset by 1chr, I think?

0atman avatar Apr 07 '25 14:04 0atman

This is tricky because the terminal is cell based. If the total amount of margin is even, we can distribute it evenly on each side so that's good. If it's odd though we can either distribute an extra one on the left or right or we can distribute it evenly but then the text won't fit anymore and we need to push a word to the next line, and even then there's no guarantee you'll have an equal amount of margin on each side.

mfontanini avatar Apr 07 '25 15:04 mfontanini

Understandable - does the kitty protocol help here? 

On April 7, 2025, GitHub @.***> wrote:

This is tricky because the terminal is cell based. If the total amount of margin is even, we can distribute it evenly on each side so that's good. If it's odd though we can either distribute an extra one on the left or right or we can distribute it evenly but then the text won't fit anymore and we need to push a word to the next line, and even then there's no guarantee you'll have an equal amount of margin on each side.

— Reply to this email directly, view it on GitHub <https://github.com/mfontanini/presenterm/issues/539#issuecomment- 2783809690>, or unsubscribe <https://github.com/notifications/unsubscribe- auth/AAA33MLKOTOBIR2HWN5FZRL2YKMI5AVCNFSM6AAAAAB2T2QEZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBTHAYDSNRZGA>. You are receiving this because you authored the thread.Message ID: @.***>

mfontanini left a comment (mfontanini/presenterm#539) <https://github.com/mfontanini/presenterm/issues/539#issuecomment- 2783809690>

This is tricky because the terminal is cell based. If the total amount of margin is even, we can distribute it evenly on each side so that's good. If it's odd though we can either distribute an extra one on the left or right or we can distribute it evenly but then the text won't fit anymore and we need to push a word to the next line, and even then there's no guarantee you'll have an equal amount of margin on each side. — Reply to this email directly, view it on GitHub <https://github.com/mfontanini/presenterm/issues/539#issuecomment- 2783809690>, or unsubscribe <https://github.com/notifications/unsubscribe- auth/AAA33MLKOTOBIR2HWN5FZRL2YKMI5AVCNFSM6AAAAAB2T2QEZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBTHAYDSNRZGA>. You are receiving this because you authored the thread.Message ID: @.***>

0atman avatar Apr 07 '25 16:04 0atman

Good point! Yeah I think printing a space with a size of 0.5 on each side should do it. This will require changing a few things but it should work fine, albeit only on kitty but that's okay.

mfontanini avatar Apr 07 '25 19:04 mfontanini

sweet! kitty is freakin' amazing. ghostty also supports kitty, which I'm excited about

0atman avatar Apr 08 '25 10:04 0atman

BTW, headings also seem to be pushed one extra chr to the right, which feels like a separate problem?

0atman avatar Apr 08 '25 10:04 0atman

Ghostty supports the kitty graphics protocol, I don't imagine they support the kitty font size one yet as it just came out.

I'll have a look at the offset problem soon, I'm AFK for a few days

mfontanini avatar Apr 08 '25 13:04 mfontanini

oh! those are different, I see! That's wonderful, and would REALLY help my OCD looking at these offbyone titles 😆 let me know if I you want a pair/test at any point! Thank you again!

0atman avatar Apr 08 '25 13:04 0atman

Alright, I'm back home and I'm looking at using fractional sizes via the kitty protocol but it won't fix the issue. Per the spec:

The fractional scale does not affect the number of cells the text occupies, instead, it just adjusts the rendered font size within those cells.

So writing a 1/2 size space won't move all the text in that row by half a cell. This makes sense and I was wondering how it dealt with it otherwise, since the terminal stops being cell based and becomes a chain of characters otherwise.

So sorry but I don't know how to fix this. There's N columns, M is taken by the text and P = (N - M) is padding. If P is odd I have no choice but to put the extra space either on the left or right or the text.

mfontanini avatar Apr 10 '25 00:04 mfontanini

Makes sense, thanks so much for doing the research, I've opened a slightly different issue about the offbyone issue specifically with centering headings: #541

0atman avatar Apr 10 '25 07:04 0atman

Closing this because unfortunately there's nothing that can be done as this is a limitation of the terminal environment.

mfontanini avatar May 31 '25 22:05 mfontanini