A-Net Online

  • Python wcwidth .. good for ansi?!

    From Dingo@911:1919/0 to All on Thu Feb 5 13:44:12 2026
    I've made a lot of updates to my python wcwidth library lately, https://wcwidth.readthedocs.io/ which might be of interest to bbs use -- because, in addition to helping measure emoji and unicode, it also now
    measures "around" terminal sequences. It even contains a VT ANSI state
    parser, and a text-wrapping function derived from standard python textwrap.wrap(). And even, if you want, to "zoom into" any piece of text containing sequences, the cut() function can also do that, I plan to
    make something cool with these effects i'll share later.

    There is also iter_sequences() function which is useful to "walk"
    sequences. And all of this is termios/fnctl/curses-free.

    Simply, you can wcwidth.center('\x1b[3mText with sequences', 80)

    text wrapping is pretty advanced, it tracks the state and terminates
    every line with a "reset" sequence and begins the next line with the
    next sequence. Anyway it's all explained in the docs, hope it is useful



    |10Dingo

    --- CNet/5
    * Origin: aBSiNTHE BBS absinthebbs.net:1940 (911:1919/0)