Skip to content

Commit 8212cf0

Browse files
committed
use the builtin _curses when possible, only use _minimal_curses as a last resort (it's broken on MacOS)
1 parent 6d04d00 commit 8212cf0

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

pyrepl/curses.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@
1919
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2020

2121

22-
from ._minimal_curses import error, setupterm, tigetstr, tparm
22+
try:
23+
import _curses
24+
except ImportError:
25+
try:
26+
import curses as _curses # type: ignore[no-redef]
27+
except ImportError:
28+
from . import _minimal_curses as _curses # type: ignore[no-redef]
29+
30+
setupterm = _curses.setupterm
31+
tigetstr = _curses.tigetstr
32+
tparm = _curses.tparm
33+
error = _curses.error

tests/test_curses.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22

33
import pytest
44

5-
import pyrepl
6-
from pyrepl.curses import setupterm
5+
from pyrepl._minimal_curses import error, setupterm
76

87

9-
def test_setupterm(monkeypatch):
8+
@pytest.mark.xfail(sys.platform == "win32", reason="windows does not have _curses")
9+
def test_imports():
10+
import _curses
11+
12+
from pyrepl.curses import error, setupterm, tigetstr, tparm
13+
14+
assert setupterm is _curses.setupterm
15+
assert tigetstr is _curses.tigetstr
16+
assert tparm is _curses.tparm
17+
assert error is _curses.error
18+
19+
20+
def test_minimal_curses_setupterm(monkeypatch):
1021
assert setupterm(None, 0) is None
1122

1223
exit_code = -1 if sys.platform == "darwin" else 0
1324
with pytest.raises(
14-
pyrepl._minimal_curses.error,
25+
error,
1526
match=rf"setupterm\(b?'term_does_not_exist', 0\) failed \(err={exit_code}\)",
1627
):
1728
setupterm("term_does_not_exist", 0)
@@ -21,7 +32,7 @@ def test_setupterm(monkeypatch):
2132

2233
monkeypatch.delenv("TERM")
2334
with pytest.raises(
24-
pyrepl._minimal_curses.error,
35+
error,
2536
match=r"setupterm\(None, 0\) failed \(err=-1\)",
2637
):
2738
setupterm(None, 0)

0 commit comments

Comments
 (0)