Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Index of element after width of characters



Hello,
I had to implement horizontal scrolling of text and noticed that Asian
characters can have width of two. Scrolling via indexes of strings was
giving different speeds to normal and to the wide characters.

I then noticed useful (m) flag that returns widths. Scrolling can be
done this way but basically it requires to output characters one by
one. I then thought about new flag. It should be handy in various
multi byte scenarios, e.g. in prompts. From submitted documentation:

y:width:
Index-post-width: for strings substitutes index of first character that is
located fully after width `width' of characters (multibyte characters may
have widths of e.g. 2, see the `m' flag). For arrays it substitutes index of
first element that appears after elements whose summed width is at least
`width'. -1 is substituted if there is no such character or array element.


Also a comment from code:
            /* Reached the width?
             * If single-width char 'd' reaches width say 4 it'll look like:
             *     abcd|ef
             * `e' is the returned (by index) character.
             *
             * If double-width char (de) reaches the width:
             *     abc(d|e)f
             * `f' is the returned (by index) character
             * */

The code works, however not in the test that I commit. Wonder why it
works in scripts and at prompt but not in the test? Output of the test
is:

*** 1,8 ****
!  1
!  2
!  2
!  3
!  3
!  4
!  -1
!  -1
--- 1,8 ----
! 1
! 8
! -1
! -1
! -1
! -1
! -1
! -1

The code should be well adapted, because it works like # flag (get
length), it's in the same place in subst.c. I hope that because of
this everything is in check. The function in Src/utils.c is a copied
and modified mature function metacharlenconv(). After things are
clarified I'll probably submit one other flag 'x' that will substitute
last index that yields width lesser than a given one (nickname
index-pre-width?). So it will be a nice mnemonic – y – after, x –
before (a width).

Best regards,
Sebastian Gniazdowski

Attachment: index-post-width.patch
Description: Binary data



Messages sorted by: Reverse Date, Date, Thread, Author