mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
Python: add full cell/ncplane APIs
This commit is contained in:
parent
fc1341ea5a
commit
26f1b50a28
@ -105,18 +105,13 @@ int notcurses_mouse_disable(struct notcurses* n);
|
||||
int ncplane_destroy(struct ncplane* ncp);
|
||||
bool notcurses_canopen(const struct notcurses* nc);
|
||||
void ncplane_erase(struct ncplane* n);
|
||||
void cell_release(struct ncplane* n, cell* c);
|
||||
int ncplane_cursor_move_yx(struct ncplane* n, int y, int x);
|
||||
void ncplane_cursor_yx(struct ncplane* n, int* y, int* x);
|
||||
int ncplane_move_yx(struct ncplane* n, int y, int x);
|
||||
void ncplane_yx(struct ncplane* n, int* y, int* x);
|
||||
void ncplane_dim_yx(struct ncplane* n, int* rows, int* cols);
|
||||
void ncplane_styles_set(struct ncplane* n, unsigned stylebits);
|
||||
int ncplane_putc_yx(struct ncplane* n, int y, int x, const cell* c);
|
||||
int ncplane_putsimple_yx(struct ncplane* n, int y, int x, char c);
|
||||
void ncplane_styles_on(struct ncplane* n, unsigned stylebits);
|
||||
void ncplane_styles_off(struct ncplane* n, unsigned stylebits);
|
||||
unsigned ncplane_styles(struct ncplane* n);
|
||||
int ncplane_move_top(struct ncplane* n);
|
||||
int ncplane_move_bottom(struct ncplane* n);
|
||||
int ncplane_move_below(struct ncplane* n, struct ncplane* below);
|
||||
@ -130,6 +125,30 @@ void* ncplane_userptr(struct ncplane* n);
|
||||
int ncplane_resize(struct ncplane* n, int keepy, int keepx, int keepleny,
|
||||
int keeplenx, int yoff, int xoff, int ylen, int xlen);
|
||||
const void* ncplane_userptr_const(const struct ncplane* n);
|
||||
uint64_t ncplane_channels(struct ncplane* n);
|
||||
uint32_t ncplane_attr(struct ncplane* n);
|
||||
unsigned ncplane_bchannel(struct ncplane* nc);
|
||||
unsigned ncplane_fchannel(struct ncplane* nc);
|
||||
unsigned ncplane_fg(struct ncplane* nc);
|
||||
unsigned ncplane_bg(struct ncplane* nc);
|
||||
unsigned ncplane_fg_alpha(struct ncplane* nc);
|
||||
unsigned ncplane_bg_alpha(struct ncplane* nc);
|
||||
unsigned ncplane_fg_rgb(struct ncplane* n, unsigned* r, unsigned* g, unsigned* b);
|
||||
unsigned ncplane_bg_rgb(struct ncplane* n, unsigned* r, unsigned* g, unsigned* b);
|
||||
int ncplane_set_fg_rgb(struct ncplane* n, int r, int g, int b);
|
||||
int ncplane_set_bg_rgb(struct ncplane* n, int r, int g, int b);
|
||||
void ncplane_set_fg_rgb_clipped(struct ncplane* n, int r, int g, int b);
|
||||
void ncplane_set_bg_rgb_clipped(struct ncplane* n, int r, int g, int b);
|
||||
int ncplane_set_fg(struct ncplane* n, unsigned channel);
|
||||
int ncplane_set_bg(struct ncplane* n, unsigned channel);
|
||||
void ncplane_set_fg_default(struct ncplane* n);
|
||||
void ncplane_set_bg_default(struct ncplane* n);
|
||||
int ncplane_set_fg_alpha(struct ncplane* n, int alpha);
|
||||
int ncplane_set_bg_alpha(struct ncplane* n, int alpha);
|
||||
void ncplane_styles_set(struct ncplane* n, unsigned stylebits);
|
||||
void ncplane_styles_on(struct ncplane* n, unsigned stylebits);
|
||||
void ncplane_styles_off(struct ncplane* n, unsigned stylebits);
|
||||
unsigned ncplane_styles(struct ncplane* n);
|
||||
typedef struct ncstats {
|
||||
uint64_t renders; // number of successful notcurses_render() runs
|
||||
uint64_t failed_renders; // number of aborted renders, should be 0
|
||||
@ -163,6 +182,45 @@ int ncplane_putwc(struct ncplane* n, wchar_t w);
|
||||
int ncplane_putegc_yx(struct ncplane* n, int y, int x, const char* gclust, int* sbytes);
|
||||
int ncplane_putstr_yx(struct ncplane* n, int y, int x, const char* gclustarr);
|
||||
int ncplane_putstr_aligned(struct ncplane* n, int y, ncalign_e align, const char* s);
|
||||
void cell_init(cell* c);
|
||||
int cell_load(struct ncplane* n, cell* c, const char* gcluster);
|
||||
int cell_prime(struct ncplane* n, cell* c, const char* gcluster, uint32_t attr, uint64_t channels);
|
||||
int cell_duplicate(struct ncplane* n, cell* targ, const cell* c);
|
||||
void cell_release(struct ncplane* n, cell* c);
|
||||
void cell_styles_set(cell* c, unsigned stylebits);
|
||||
unsigned cell_styles(const cell* c);
|
||||
void cell_styles_on(cell* c, unsigned stylebits);
|
||||
void cell_styles_off(cell* c, unsigned stylebits);
|
||||
void cell_set_fg_default(cell* c);
|
||||
void cell_set_bg_default(cell* c);
|
||||
int cell_set_fg_alpha(cell* c, int alpha);
|
||||
int cell_set_bg_alpha(cell* c, int alpha);
|
||||
bool cell_double_wide_p(const cell* c);
|
||||
bool cell_simple_p(const cell* c);
|
||||
const char* cell_extended_gcluster(const struct ncplane* n, const cell* c);
|
||||
bool cell_noforeground_p(const cell* c);
|
||||
int cell_load_simple(struct ncplane* n, cell* c, char ch);
|
||||
uint32_t cell_egc_idx(const cell* c);
|
||||
unsigned cell_bchannel(const cell* cl);
|
||||
unsigned cell_fchannel(const cell* cl);
|
||||
uint64_t cell_set_bchannel(cell* cl, uint32_t channel);
|
||||
uint64_t cell_set_fchannel(cell* cl, uint32_t channel);
|
||||
uint64_t cell_blend_fchannel(cell* cl, unsigned channel, unsigned blends);
|
||||
uint64_t cell_blend_bchannel(cell* cl, unsigned channel, unsigned blends);
|
||||
unsigned cell_fg(const cell* cl);
|
||||
unsigned cell_bg(const cell* cl);
|
||||
unsigned cell_fg_alpha(const cell* cl);
|
||||
unsigned cell_bg_alpha(const cell* cl);
|
||||
unsigned cell_fg_rgb(const cell* cl, unsigned* r, unsigned* g, unsigned* b);
|
||||
unsigned cell_bg_rgb(const cell* cl, unsigned* r, unsigned* g, unsigned* b);
|
||||
int cell_set_fg_rgb(cell* cl, int r, int g, int b);
|
||||
int cell_set_bg_rgb(cell* cl, int r, int g, int b);
|
||||
void cell_set_fg_rgb_clipped(cell* cl, int r, int g, int b);
|
||||
void cell_set_bg_rgb_clipped(cell* cl, int r, int g, int b);
|
||||
int cell_set_fg(cell* c, uint32_t channel);
|
||||
int cell_set_bg(cell* c, uint32_t channel);
|
||||
bool cell_fg_default_p(const cell* cl);
|
||||
bool cell_bg_default_p(const cell* cl);
|
||||
""")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -2,6 +2,14 @@ import sys
|
||||
import locale
|
||||
from _notcurses import lib, ffi
|
||||
|
||||
def checkRGB(r, g, b):
|
||||
if r < 0 or r > 255:
|
||||
raise ValueError("Bad red value")
|
||||
if g < 0 or g > 255:
|
||||
raise ValueError("Bad green value")
|
||||
if b < 0 or b > 255:
|
||||
raise ValueError("Bad blue value")
|
||||
|
||||
class Cell:
|
||||
def __init__(self, ncplane):
|
||||
self.c = ffi.new("cell *")
|
||||
@ -20,7 +28,7 @@ class Cell:
|
||||
raise ValueError("Bad green value")
|
||||
if b < 0 or b > 255:
|
||||
raise ValueError("Bad blue value")
|
||||
self.c.channels = r * 65536 + g * 256 + b # FIXME
|
||||
lib.cell_set_bg_rgb(self.c, r, g, b)
|
||||
|
||||
def getNccell(self):
|
||||
return self.c
|
||||
@ -44,6 +52,10 @@ class Ncplane:
|
||||
lib.ncplane_dim_yx(self.n, y, x)
|
||||
return (y[0], x[0])
|
||||
|
||||
def setFgRGB(self, r, g, b):
|
||||
checkRGB(r, g, b)
|
||||
lib.ncplane_set_fg_rgb(self.n, r, g, b)
|
||||
|
||||
class Notcurses:
|
||||
def __init__(self):
|
||||
opts = ffi.new("notcurses_options *")
|
||||
@ -67,7 +79,18 @@ if __name__ == '__main__':
|
||||
c.setBgRGB(0x80, 0xc0, 0x80)
|
||||
nc.stdplane().setBase(c)
|
||||
dims = nc.stdplane().getDimensions()
|
||||
r = 0x80
|
||||
g = 0x80
|
||||
b = 0x80
|
||||
for y in range(dims[0]):
|
||||
for x in range(dims[1]):
|
||||
nc.stdplane().setFgRGB(r, g, b)
|
||||
nc.stdplane().putSimpleYX(y, x, b'X')
|
||||
b = b + 2
|
||||
if b == 256:
|
||||
b = 0
|
||||
g = g + 2
|
||||
if g == 256:
|
||||
g = 0
|
||||
r = r + 2
|
||||
nc.render()
|
||||
|
Loading…
x
Reference in New Issue
Block a user