python for ncdirect

This commit is contained in:
nick black 2020-02-04 04:16:16 -05:00
parent 5cd3a4c41d
commit ab3a91c5d0
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
6 changed files with 48 additions and 14 deletions

View File

@ -516,10 +516,11 @@ if(${BUILD_PYTHON})
"execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --root=${CMAKE_SOURCE_DIR}/debian/python3-notcurses --install-layout=deb --prefix=${CMAKE_INSTALL_PREFIX} --skip-build
WORKING_DIRECTORY
../python)"
)
)
else()
install(
CODE
"execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})")
"execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})"
)
endif()
endif()

View File

@ -281,7 +281,6 @@ typedef struct selector_options {
uint64_t bgchannels; // background channels, used only in body
} selector_options;
struct ncselector* ncselector_create(struct ncplane* n, int y, int x, const selector_options* opts);
struct ncselector* ncselector_aligned(struct ncplane* n, int y, ncalign_e align, const selector_options* opts);
int ncselector_additem(struct ncselector* n, const struct selector_item* item);
int ncselector_delitem(struct ncselector* n, const char* item);
char* ncselector_selected(const struct ncselector* n);

View File

@ -75,6 +75,30 @@ class Notcurses:
def stdplane(self):
return self.stdncplane
class Ncdirect:
def __init__(self):
self.nc = lib.notcurses_directmode(ffi.NULL, sys.stdout)
def __del__(self):
lib.ncdirect_stop(self.nc)
# FIXME ought be checking for errors on the actual library calls, also
def setFgRGB8(self, r, g, b):
checkRGB8(r, g, b)
lib.ncdirect_fg_rgb8(self.nc, r, g, b)
def setBgRGB8(self, r, g, b):
checkRGB8(r, g, b)
lib.ncdirect_bg_rgb8(self.nc, r, g, b)
def setFg(self, rgb):
checkRGB(rgb)
lib.ncdirect_fg(self.nc, rgb)
def setBg(self, rgb):
checkRGB(rgb)
lib.ncdirect_bg(self.nc, rgb)
if __name__ == '__main__':
locale.setlocale(locale.LC_ALL, "")
nc = Notcurses()

View File

@ -613,30 +613,42 @@ int ncdirect_bg(ncdirect* nc, unsigned rgb){
if(rgb > 0xffffffu){
return -1;
}
return term_bg_rgb8(nc->RGBflag, nc->setab, nc->colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu);
if(term_bg_rgb8(nc->RGBflag, nc->setab, nc->colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu)){
return -1;
}
return fflush(stdout);
}
int ncdirect_fg(ncdirect* nc, unsigned rgb){
if(rgb > 0xffffffu){
return -1;
}
return term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu);
if(term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu)){
return -1;
}
return fflush(stdout);
}
int ncdirect_bg_rgb8(ncdirect* nc, unsigned r, unsigned g, unsigned b){
if(r > 255 || g > 255 || b > 255){
return -1;
}
return term_bg_rgb8(nc->RGBflag, nc->setab, nc->colors, nc->ttyfp, r, g, b);
if(term_bg_rgb8(nc->RGBflag, nc->setab, nc->colors, nc->ttyfp, r, g, b)){
return -1;
}
return fflush(stdout);
}
int ncdirect_fg_rgb8(ncdirect* nc, unsigned r, unsigned g, unsigned b){
if(r > 255 || g > 255 || b > 255){
return -1;
}
return term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp, r, g, b);
if(term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp, r, g, b)){
return -1;
}
return fflush(stdout);
}
static inline int

View File

@ -230,8 +230,6 @@ freeitems:
return NULL;
}
ncselector* ncselector_aligned(ncplane* n, int y, ncalign_e align, const selector_options* opts);
int ncselector_additem(ncselector* n, const struct selector_item* item){
size_t newsize = sizeof(*n->items) * (n->itemcount + 1);
struct selector_item* items = realloc(n->items, newsize);

View File

@ -21,7 +21,7 @@ print_b(struct ncdirect* nc, int r, int g, int total){
static int
print_gb(struct ncdirect* nc, int r, int total){
for(int g = 0xf ; g <= total - r && g < 256 ; g += 16){
for(int g = 0 ; g <= total - r && g < 256 ; g += 4){
if(print_b(nc, r, g, total)){
return -1;
}
@ -31,7 +31,7 @@ print_gb(struct ncdirect* nc, int r, int total){
static int
print_rgb(struct ncdirect* nc, int total){
for(int r = 0xf ; r <= total && r < 256 ; r += 16){
for(int r = 0 ; r <= total && r < 256 ; r += 4){
if(print_gb(nc, r, total)){
return -1;
}
@ -48,7 +48,7 @@ int main(void){
if(!nc){
return EXIT_FAILURE;
}
for(int t = 0xf ; t < 768 ; t += 16){
for(int t = 0 ; t < 768 ; t += 4){
if(print_rgb(nc, t)){
ncdirect_stop(nc);
return EXIT_FAILURE;