Skip to content

Commit cd478d4

Browse files
committed
gh-155499: Allow zero defaults with wide curses borders
1 parent 7571c41 commit cd478d4

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/test/test_curses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ def test_wide_characters(self):
467467
if self._encodable(vline + hline):
468468
stdscr.border(vline, vline, hline, hline)
469469
stdscr.box(vline, hline)
470+
# Zero still requests the default character in the wide path.
471+
stdscr.border('|', '|', '-', '-', 0, 0, 0, 0)
472+
stdscr.box('|', 0)
473+
stdscr.box(0, '-')
470474
# border() and box() cannot mix integer and wide-string characters.
471475
self.assertRaises(TypeError, stdscr.box, vline, ord('-'))
472476

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :meth:`~curses.window.border` and :meth:`~curses.window.box` to accept the
2+
documented ``0`` default character alongside strings.

Modules/_cursesmodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
27052705
}
27062706
if (use_wide) {
27072707
for (i = 0; i < 8; i++) {
2708-
if (objs[i] == NULL) {
2708+
if (objs[i] == NULL || (types[i] == 1 && ch[i] == 0)) {
27092709
wch_p[i] = NULL; /* use the default character */
27102710
}
27112711
else if (types[i] == 2) {
@@ -2775,13 +2775,15 @@ _curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,
27752775
}
27762776
}
27772777
if (t1 == 2 || t2 == 2) {
2778-
if (t1 != 2 || t2 != 2) {
2778+
if ((t1 != 2 && ch1 != 0) || (t2 != 2 && ch2 != 0)) {
27792779
PyErr_SetString(PyExc_TypeError,
27802780
"box() cannot mix integer or bytes characters "
27812781
"with wide string characters");
27822782
return NULL;
27832783
}
2784-
int rtn = wborder_set(self->win, &wch1, &wch1, &wch2, &wch2,
2784+
const cchar_t *wch1_p = t1 == 2 ? &wch1 : NULL;
2785+
const cchar_t *wch2_p = t2 == 2 ? &wch2 : NULL;
2786+
int rtn = wborder_set(self->win, wch1_p, wch1_p, wch2_p, wch2_p,
27852787
NULL, NULL, NULL, NULL);
27862788
return curses_window_check_err(self, rtn, "wborder_set", "box");
27872789
}

0 commit comments

Comments
 (0)