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

ncplane_puttext causes infinite plane resizing #2771

Open
lokxii opened this issue Mar 24, 2024 · 7 comments
Open

ncplane_puttext causes infinite plane resizing #2771

lokxii opened this issue Mar 24, 2024 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lokxii
Copy link

lokxii commented Mar 24, 2024

I have this following code that causes the problem

int main() {
    setlocale(LC_ALL, "");
    notcurses* nc = NULL;
    notcurses_options opt = {
        .loglevel = NCLOGLEVEL_TRACE,
        .flags = NCOPTION_NO_QUIT_SIGHANDLERS | NCOPTION_SUPPRESS_BANNERS
    };
    if ((nc = notcurses_init(&opt, NULL)) == NULL) {
        exit(EXIT_FAILURE);
    }

    ncplane* stdplane = notcurses_stdplane(nc);
    ncplane_options testplane_opt = {
        .rows = 1,
        .cols = 48,
        .flags = NCPLANE_OPTION_AUTOGROW | NCPLANE_OPTION_VSCROLL
    };
    ncplane* n = ncplane_create(stdplane, &testplane_opt);
    std::string text = "おなかがすいたし眠いのでナイトシティに帰ります\n私は最寄駅のことをナイトシティと2分前から呼んでいます";
    float cols = ncplane_puttext(
        n, 0, NCALIGN_LEFT, text.c_str(), NULL);

    notcurses_render(nc);

    ncinput ni;
    while (notcurses_get_blocking(nc, &ni) == -1 || ni.id == 27) {}
    notcurses_stop(nc);

    return 0;
}

I am using notcurses just compiled from latest commit on master branch, an Kitty terminal v0.31.0
When I remove the number 2 from the string, ncplane_puttext prints the string properly.

@lokxii lokxii added the bug Something isn't working label Mar 24, 2024
@lokxii
Copy link
Author

lokxii commented Mar 24, 2024

I can only tell that some calculations are wrong in this function to cause *bytes not being properly set, causing the do while loop in ncplane_puttext() to loop infinitely

@lokxii
Copy link
Author

lokxii commented Mar 24, 2024

ncplane_puttext() can print text normally when I add one more 1 column wide character to the second line of the string. For example

    std::string text = "おなかがすいたし眠いのでナイトシティに帰ります\n私は最寄駅のことをナイトシティと22分前から呼んでいます";

@dankamongmen dankamongmen self-assigned this Mar 25, 2024
@dankamongmen dankamongmen added this to the 3.1.0 milestone Mar 25, 2024
@dankamongmen
Copy link
Owner

thanks for the report! i'll look into this as soon as i can, hopefully very soon.

@lokxii
Copy link
Author

lokxii commented Mar 25, 2024

I replaced my use of ncplane_puttext() with ncplane_putstr_yx() because I only need to print align to left. Then I realized why do we need ncplane_puttext() when ncplane_putstr*() basically do all the jobs of ncplane_puttext()?

@dankamongmen
Copy link
Owner

I replaced my use of ncplane_puttext() with ncplane_putstr_yx() because I only need to print align to left. Then I realized why do we need ncplane_puttext() when ncplane_putstr*() basically do all the jobs of ncplane_puttext()?

ncplane_puttext() does way more than ncplane_putstr(). it's intended for putting multiple lines of text.

@lokxii
Copy link
Author

lokxii commented Mar 25, 2024

Interesting. Cuz I used ncplane_putstr_yx() to print that multiline string to give the expected result of ncplane_puttext()

Edit: sorry, pressed the wrong button closing the commit

@lokxii lokxii closed this as completed Mar 25, 2024
@lokxii lokxii reopened this Mar 25, 2024
@dankamongmen
Copy link
Owner

Interesting. Cuz I used ncplane_putstr_yx() to print that multiline string to give the expected result of ncplane_puttext()

yeah, ncplane_putstr() will move to the next line, but it won't intelligently split lines so that words aren't broken across lines etc.

Edit: sorry, pressed the wrong button closing the commit

no worries! i definitely want to get this resolved either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants