bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting cchar_t to wchar_t


From: Bryan Christ
Subject: Re: Converting cchar_t to wchar_t
Date: Fri, 14 Jun 2019 13:28:12 -0500

Ya.  I realized that I could use getcchar() and setcchar() to handle the conversion.  The root of my problem is that Mac OS appears to handle this code...

wattr_set(vterm->window, attrs, colors, NULL);
mvwadd_wch(vterm->window, r, c, &vcell->uch);

...slightly different on FreeBSD and Linux when the attributes in cchar_t (in this case vcell->uch) are not set.  On FreeBSD and Linux the attrs from the wattr_set() are honored in the final render.  On Mac OS, the cchar_t members attr and ext_colors appear to trump the other during the final render--effectively rendering them not visible.  There may be more to this than meets the eye, but specifically syncing them up with setcchar() solves the problem.

On Fri, Jun 14, 2019 at 1:19 PM Mike Gran <address@hidden> wrote:
On Fri, Jun 14, 2019 at 11:32:06AM -0500, Bryan Christ wrote:
> This code works in Linux and FreeBSD but I suspect is not working on Mac OS
> because of how NCURSES_WACS() may be implemented on Mac OS.

Hi,

I think the canonical way of doing it would be something like the following.
Remember that a cchar_t may be more than one character, because a cchar_t
can represent more than one character overstriking the same location.

Regards,

Mike Gran

----

  // Given a cchar_t * named x
  attr_t attr;
  short color_pair;
  size_t len;

  len = getcchar (x, 0, 0, 0, 0);
  /* Starting from the patch on 2009/07/18, the length returned by
     getcchar includes the trailing NULL.  Prior to that, it did not
     include the trailing NULL. */
  if (NCURSES_VERSION_MAJOR > 5
     || (NCURSES_VERSION_MAJOR == 5 && NCURSES_VERSION_MINOR > 7)
     || (NCURSES_VERSION_MAJOR == 5 && NCURSES_VERSION_MINOR == 7
      && NCURSES_VERSION_PATCH >= 20090718))
         len--;

  wchar_t *wch = calloc(len + 1, sizeof(wchar_t));

  ret = getcchar (x, wch, &attr, &color_pair, NULL);



--
Bryan
<><

reply via email to

[Prev in Thread] Current Thread [Next in Thread]