From f049b61b3434c619610c9e1054f43e65c3be75c6 Mon Sep 17 00:00:00 2001 From: Alex Samuel Date: Tue, 15 Feb 2022 23:45:00 -0500 Subject: [PATCH] [py] Split out fg and bg params to box(). --- python/examples/009-box.py | 14 +++++++------- python/notcurses/functions.c | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/python/examples/009-box.py b/python/examples/009-box.py index c11b444c2..e552a3d10 100644 --- a/python/examples/009-box.py +++ b/python/examples/009-box.py @@ -13,22 +13,22 @@ BOX_CHARS = ( nc.NCBOXROUND, ) -CHANNELS = ( - 0, - 0x0000000040808080, # default on grey - 0x40ff000000000000, # red on default - 0x4000ff00400000ff, # green on blue +COLORS = ( + (0x00000000, 0x00000000), + (0x00000000, 0x40808080), # default on grey + (0x40ff0000, 0x00000000), # red on default + (0x4000ff00, 0x400000ff), # green on blue ) SY = 7 SX = 10 -for y, channels in enumerate(CHANNELS): +for y, (fg, bg) in enumerate(COLORS): for x, box_chars in enumerate(BOX_CHARS): nc.box( plane, (y + 1) * SY - 1, (x + 1) * SX - 1, y * SY + 1, x * SX + 1, box_chars, - channels=channels, + fg=fg, bg=bg, # ctlword=0x1f9 ) diff --git a/python/notcurses/functions.c b/python/notcurses/functions.c index 91f1dd7d5..91bd822ca 100644 --- a/python/notcurses/functions.c +++ b/python/notcurses/functions.c @@ -4,17 +4,16 @@ #include "notcurses-python.h" // TODO: function to construct channels: channel(None | pindex | color, alpha=0) -// TODO: split channels into two args // TODO: perimeter version // TODO: rationalize coordinate / size args -// TODO: provide a way to set channels for each corne +// TODO: provide a way to set channels for each corner // TODO: docstring -// TODO: test +// TODO: unit test static PyObject* pync_meth_box(PyObject* Py_UNUSED(self), PyObject* args, PyObject* kwargs) { static char* keywords[] = { - "plane", "ystop", "xstop", "y", "x", "box_chars", "styles", "channels", + "plane", "ystop", "xstop", "y", "x", "box_chars", "styles", "fg", "bg", "ctlword", NULL }; NcPlaneObject* plane_arg; @@ -24,20 +23,21 @@ pync_meth_box(PyObject* Py_UNUSED(self), PyObject* args, PyObject* kwargs) { int x = -1; const char* box_chars = NCBOXASCII; uint16_t styles = 0; - uint64_t channels = 0; + uint32_t fg = 0; + uint32_t bg = 0; unsigned ctlword = 0; if (!PyArg_ParseTupleAndKeywords( - args, kwargs, "O!II|iis$HKI:box", keywords, + args, kwargs, "O!II|iis$HIII:box", keywords, &NcPlane_Type, &plane_arg, - &ystop, &xstop, &y, &x, &box_chars, &styles, &channels, &ctlword)) + &ystop, &xstop, &y, &x, &box_chars, &styles, &fg, &bg, &ctlword)) return NULL; + struct ncplane* const plane = plane_arg->ncplane_ptr; + if (!notcurses_canutf8(ncplane_notcurses(plane))) // No UTF-8 support; force ASCII. box_chars = NCBOXASCII; - struct ncplane* const plane = plane_arg->ncplane_ptr; - int ret; nccell ul = NCCELL_TRIVIAL_INITIALIZER; nccell ur = NCCELL_TRIVIAL_INITIALIZER; @@ -45,6 +45,7 @@ pync_meth_box(PyObject* Py_UNUSED(self), PyObject* args, PyObject* kwargs) { nccell lr = NCCELL_TRIVIAL_INITIALIZER; nccell hl = NCCELL_TRIVIAL_INITIALIZER; nccell vl = NCCELL_TRIVIAL_INITIALIZER; + uint64_t channels = (uint64_t) fg << 32 | bg; ret = nccells_load_box( plane, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl, box_chars); if (ret == -1) {