Skip to content

Unexpected behaviour with NCPLANE_OPTION_MARGINALIZED and ncplane_resize_marginalized #2913

@sinny-13

Description

@sinny-13

notcurses 3.0.17

I have been trying to use NCPLANE_OPTION_MARGINALIZED along with its recommended resize callback, ncplane_resize_marginalized, and I cannot get it to work as expected. I expect that I'm using it incorrectly, and would enjoy being told so!

Main terminal:

COLORTERM=truecolor
LANG=en_GB.UTF-8
TERM=xterm-ghostty
TERM_PROGRAM=ghostty
TERM_PROGRAM_VERSION=1.2.3

Same behaviour with:

LANG=en_GB.UTF-8
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=455.1

as well as:

COLORTERM=truecolor
LANG=en_GB.UTF-8
LC_TERMINAL=iTerm2
LC_TERMINAL_VERSION=3.5.14
TERM=xterm-256color
TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.5.14

I’ve built a fairly minimal example of it not working.

There seems to be two issues:

  • The initial plane which should have a margin of 1 on each side, only has a margin on the left, and top.
  • The resize sets the position of the inner plane somewhere way off.

Below is my main.c:

#include <locale.h>
#include <notcurses/notcurses.h>
#include <unistd.h>

int main(void) {

  setlocale(LC_ALL, "");

  struct notcurses_options opts = {.termtype = NULL};
  struct notcurses *nc = notcurses_init(&opts, NULL);
  if (!nc)
    return 1;

  struct ncplane *pl_std = notcurses_stdplane(nc);
  struct ncplane_options base_opts = {
      .cols = 40, .rows = 20, .x = 0, .y = 0, .name = "base"};
  struct ncplane *base = ncplane_create(pl_std, &base_opts);
  ncplane_set_base(base, "x", 0,
                   NCCHANNELS_INITIALIZER(0x10, 0x70, 0x00, 0x00, 0x00, 0x00));
  ncplane_erase(base);

  struct ncplane_options marg_p_opts = {.name = "marg",
                                        .cols = 0,
                                        .rows = 0,
                                        .x = 1,
                                        .y = 1,
                                        .margin_r = 1,
                                        .margin_b = 1,
                                        .resizecb =
                                            &ncplane_resize_marginalized,
                                        .flags = NCPLANE_OPTION_MARGINALIZED};
  struct ncplane *marg_p = ncplane_create(base, &marg_p_opts);
  ncplane_set_base(marg_p, "-", 0,
                   NCCHANNELS_INITIALIZER(0x00, 0x00, 0x00, 0x10, 0x70, 0x00));
  ncplane_erase(marg_p);

  notcurses_render(nc);
  sleep(4);

  ncplane_resize_simple(base, 10, 20);

  notcurses_render(nc);
  sleep(4);

  notcurses_stop(nc);
  return 0;
}

This image shows the initial planes, the inner of which should have a border of 1 on all edges.

Image

This shows the planes after the call to ncplane_resize_simple, where the position of the inner plane is incorrect.

Image

Any guidance would be appreciated.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions