Glyphs and graphemes [was Re: Cult-like behaviour]

Marko Rauhamaa marko at pacujo.net
Tue Jul 17 05:03:38 EDT 2018


Chris Angelico <rosuav at gmail.com>:

> On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> For me, the issue is where do I produce a line break in my text output?
>> Currently, I'm just counting codepoints to estimate the width of the
>> output.
>
> Well, that's just flat out wrong, then. Counting graphemes isn't going
> to make it any better. Grab a well-known library like Pango and let it
> do your measurements for you, *in pixels*. Or better still, just poke
> your text to a dedicated text-display widget and let it display it
> correctly.

What I'd need is for the tty to tell me what column the cursor is
visually. Or better yet, the tty would have to tell me where the column
would be *after* I emit the next grapheme cluster.

The tty *does* know that but I don't know if there is an interface to
query it. This doesn't seem to be working properly:

    sys.stdout.write("a\u0300\u001b[6n\n")

(and would be a tricky interface even if it did)


Marko



More information about the Python-list mailing list