Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ncegc_len function to API #2742

Closed
wants to merge 1 commit into from

Conversation

neurocyte
Copy link
Contributor

This exposes utf8_egc_len in the notcurses api as ncegc_len.

I need to use this function internally in my text editor to make sure my width and clustering calculations match up with notcurses' view of the world.

Ideally, at somepoint, I would like to abstract out notcurses usage of unicode (libunistring iirc) so that I can replace it with the same library that my text editor and/or terminal is using.

Comments very welcome.

@dankamongmen dankamongmen self-requested a review December 22, 2023 12:35
@dankamongmen
Copy link
Owner

hrmmm, i thought this was exposed.

let me think for a minute about why it wasn't. i feel the lack of it in the API must have been a conscious decision...

i guess i was that i felt you ought be working with nccells, and for them you have e.g. nccell_load(), which returns the number of bytes. does that make sense for you? that's only at load time. let me see if there's a function to get the length from an existing nccell...

i mean, there's no reason we can't export this, i just felt that a need for it indicated a less-than-optimal design.

@dankamongmen
Copy link
Owner

nccell_cols() gives you the column width. is there not an nccell_strlen() or something? looking...

@dankamongmen
Copy link
Owner

hrmmm nope it doesn't look like there is. it appears that calculation of the length of an nccell() is o(n) on the length.

soooooooooooo i feel you ought have the necessary information available from nccell_load() etc, though not if you're dumping into the ncplane via other methods, perhaps...can you quickly illustrate the need for this externally? i might be able to suggest a better way to do it. i feel i'd prefer export an nccell_strlen() (or something) if that'll work for you (and might want to implement that regardless).

@neurocyte
Copy link
Contributor Author

neurocyte commented Dec 22, 2023

My usage of this function is almost entirely off screen. I am writing a text editor and ncegc_len is used internally by the buffer manipulation layer during edit operations. That entire layer is actully independant of notcurses, except for this one function.

The overlap to notcurses come swhen, for example, deciding which part of the virtual buffer is visible on screen. And that requires that the mapping to rows and columns in the off screen buffer matches with notcurses exactly.

I guess I could do it somehow with the nccell api, but that seemed like the wrong api to me. I would be wrapping an higher level api to give me the same result as the lower level api.

@neurocyte neurocyte closed this Feb 8, 2024
@neurocyte neurocyte deleted the ncegc_len branch February 8, 2024 19:36
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