notcurses.py: define ncoptions, raise exception on init failure #807

pull/816/head
nick black 4 years ago
parent 26ae8cda5b
commit 32277ab2b9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -5,6 +5,20 @@ import locale
import _cffi_backend
from _notcurses import lib, ffi
NCOPTION_INHIBIT_SETLOCALE = 0x0001
NCOPTION_VERIFY_SIXEL = 0x0002
NCOPTION_NO_WINCH_SIGHANDLER = 0x0004
NCOPTION_NO_QUIT_SIGHANDLERS = 0x0008
NCOPTION_RETAIN_CURSOR = 0x0010
NCOPTION_SUPPRESS_BANNERS = 0x0020
NCOPTION_NO_ALTERNATE_SCREEN = 0x0040
NCOPTION_NO_FONT_CHANGES = 0x0080
class NotcursesError(Exception):
"""Base class for notcurses exceptions."""
def __init__(self, message):
self.message = message
def checkRGB(r, g, b):
if r < 0 or r > 255:
raise ValueError("Bad red value")
@ -82,8 +96,10 @@ class Ncplane:
class Notcurses:
def __init__(self):
opts = ffi.new("notcurses_options *")
opts.inhibit_alternate_screen = True
opts.flags = NCOPTION_NO_ALTERNATE_SCREEN
self.nc = lib.notcurses_init(opts, sys.stdout)
if not self.nc:
raise NotcursesError("Error initializing notcurses")
self.stdncplane = Ncplane(lib.notcurses_stdplane(self.nc))
def __del__(self):

Loading…
Cancel
Save