add notcurses_cantruecolor()

This commit is contained in:
nick black 2020-06-18 11:04:29 -04:00
parent 5a466ade18
commit 79d3ae67e4
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
8 changed files with 35 additions and 25 deletions

View File

@ -7,6 +7,9 @@ rearrangements of Notcurses.
* `ncdirect_render_image()` has been added, allowing images to be * `ncdirect_render_image()` has been added, allowing images to be
rendered in direct mode. rendered in direct mode.
* `ncvisual_geom()` now takes scaling into account. * `ncvisual_geom()` now takes scaling into account.
* **notcurses_cantruecolor()** has been added, allowing clients to
determine whether the full RGB space is available to us. If not,
we only have palette-indexed pseudocolor.
* 1.5.1 (2020-07-15) * 1.5.1 (2020-07-15)
* The semantics of rendering have changed slightly. In 1.5.0 and prior * The semantics of rendering have changed slightly. In 1.5.0 and prior

View File

@ -237,6 +237,9 @@ int notcurses_palette_size(const struct notcurses* nc);
// Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability. // Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability.
bool notcurses_canfade(const struct notcurses* nc); bool notcurses_canfade(const struct notcurses* nc);
// Can we directly specify RGB values per cell, or only use palettes?
bool notcurses_can_truecolor(const struct notcurses* nc);
// Can we load images? This requires being built against FFmpeg/OIIO. // Can we load images? This requires being built against FFmpeg/OIIO.
bool notcurses_canopen_images(const struct notcurses* nc); bool notcurses_canopen_images(const struct notcurses* nc);

View File

@ -137,7 +137,8 @@ previous action.
**ncurses(3NCURSES)**, **ncurses(3NCURSES)**,
**notcurses-demo(1)**, **notcurses-demo(1)**,
**notcurses-input(1)**, **notcurses-input(1)**,
**notcurses_cell(3)**, **notcurses_channels(3)**, **notcurses_cell(3)**,
**notcurses_channels(3)**,
**notcurses_directmode(3)**, **notcurses_directmode(3)**,
**notcurses_error(3)**, **notcurses_error(3)**,
**notcurses_fade(3)**, **notcurses_fade(3)**,
@ -157,7 +158,8 @@ previous action.
**notcurses_render(3)**, **notcurses_render(3)**,
**notcurses_selector(3)**, **notcurses_selector(3)**,
**notcurses_stats(3)**, **notcurses_stats(3)**,
**notcurses_stdplane(3)**, **notcurses_stop(3)**, **notcurses_stdplane(3)**,
**notcurses_stop(3)**,
**notcurses_visual(3)**, **notcurses_visual(3)**,
**terminfo(5)**, **ascii(7)**, **utf-8(7)**, **terminfo(5)**, **ascii(7)**, **utf-8(7)**,
**unicode(7)** **unicode(7)**

View File

@ -17,6 +17,8 @@ typedef struct palette256 {
} palette256; } palette256;
``` ```
**bool notcurses_cantruecolor(const struct notcurses* nc);**
**palette256* palette256_new(struct notcurses* nc);** **palette256* palette256_new(struct notcurses* nc);**
**int palette256_use(struct notcurses* nc, const palette256* p);** **int palette256_use(struct notcurses* nc, const palette256* p);**

View File

@ -1148,6 +1148,9 @@ API unsigned notcurses_supported_styles(const struct notcurses* nc);
// more colors than they actually support, downsampling internally. // more colors than they actually support, downsampling internally.
API int notcurses_palette_size(const struct notcurses* nc); API int notcurses_palette_size(const struct notcurses* nc);
// Can we directly specify RGB values per cell, or only use palettes?
API bool notcurses_cantruecolor(const struct notcurses* nc);
// Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability. // Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability.
API bool notcurses_canfade(const struct notcurses* nc); API bool notcurses_canfade(const struct notcurses* nc);
@ -1163,7 +1166,7 @@ API bool notcurses_canopen_videos(const struct notcurses* nc);
// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
API bool notcurses_canutf8(const struct notcurses* nc); API bool notcurses_canutf8(const struct notcurses* nc);
// Can we blit to Sixel? This requires being built against libsixel. // Can we blit to Sixel?
API bool notcurses_cansixel(const struct notcurses* nc); API bool notcurses_cansixel(const struct notcurses* nc);
typedef struct ncstats { typedef struct ncstats {

View File

@ -104,6 +104,7 @@ typedef enum {
struct ncplane* ncplane_aligned(struct ncplane* n, int rows, int cols, int yoff, ncalign_e align, void* opaque); struct ncplane* ncplane_aligned(struct ncplane* n, int rows, int cols, int yoff, ncalign_e align, void* opaque);
unsigned notcurses_supported_styles(const struct notcurses* nc); unsigned notcurses_supported_styles(const struct notcurses* nc);
int notcurses_palette_size(const struct notcurses* nc); int notcurses_palette_size(const struct notcurses* nc);
bool notcurses_cantruecolor(const struct notcurses* nc);
bool notcurses_canfade(const struct notcurses* nc); bool notcurses_canfade(const struct notcurses* nc);
bool notcurses_canchangecolor(const struct notcurses* nc); bool notcurses_canchangecolor(const struct notcurses* nc);
bool notcurses_canopen_images(const struct notcurses* nc); bool notcurses_canopen_images(const struct notcurses* nc);

View File

@ -41,6 +41,10 @@ fetch_env_vars(fetched_info* fi){
static distro_info distros[] = { static distro_info distros[] = {
{ {
.name = "arch",
// from core/filesystem
.logofile = "/usr/share/pixmaps/archlinux.png",
}, {
.name = "debian", .name = "debian",
// from desktop-base package // from desktop-base package
.logofile = "/usr/share/desktop-base/debian-logos/logo-text-256.png", .logofile = "/usr/share/desktop-base/debian-logos/logo-text-256.png",
@ -116,7 +120,7 @@ fetch_x_props(fetched_info* fi){
} }
static const distro_info* static const distro_info*
getdistro(fetched_info* fi){ linux_ncneofetch(fetched_info* fi){
FILE* osinfo = fopen("/etc/os-release", "re"); FILE* osinfo = fopen("/etc/os-release", "re");
if(osinfo == NULL){ if(osinfo == NULL){
return NULL; return NULL;
@ -187,17 +191,6 @@ unix_gethostname(fetched_info* fi){
return -1; return -1;
} }
static const distro_info*
linux_ncneofetch(fetched_info* fi){
const distro_info* dinfo = getdistro(fi);
if(dinfo == NULL){
return NULL;
}
unix_gethostname(fi);
unix_getusername(fi);
return dinfo;
}
typedef enum { typedef enum {
NCNEO_LINUX, NCNEO_LINUX,
NCNEO_FREEBSD, NCNEO_FREEBSD,
@ -260,8 +253,7 @@ freebsd_ncneofetch(fetched_info* fi){
.name = "FreeBSD", .name = "FreeBSD",
.logofile = NULL, // FIXME .logofile = NULL, // FIXME
}; };
unix_gethostname(fi); (void)fi; // FIXME set up distro_pretty
unix_getusername(fi);
return &fbsd; return &fbsd;
} }
@ -370,7 +362,9 @@ struct marshal {
static void* static void*
display_thread(void* vmarshal){ display_thread(void* vmarshal){
struct marshal* m = vmarshal; struct marshal* m = vmarshal;
display(m->nc, m->dinfo); if(m->dinfo){
display(m->nc, m->dinfo);
}
drawpalette(m->nc); drawpalette(m->nc);
sem_post(&m->sem); sem_post(&m->sem);
pthread_detach(pthread_self()); pthread_detach(pthread_self());
@ -398,14 +392,12 @@ ncneofetch(struct notcurses* nc){
.dinfo = fi.distro, .dinfo = fi.distro,
}; };
sem_init(&display_marshal.sem, 0, 0); sem_init(&display_marshal.sem, 0, 0);
if(fi.distro){ pthread_t tid;
pthread_t tid; if(pthread_create(&tid, NULL, display_thread, &display_marshal)){
if(pthread_create(&tid, NULL, display_thread, &display_marshal)){
sem_post(&display_marshal.sem);
}
}else{
sem_post(&display_marshal.sem); sem_post(&display_marshal.sem);
} }
unix_gethostname(&fi);
unix_getusername(&fi);
fetch_env_vars(&fi); fetch_env_vars(&fi);
fetch_x_props(&fi); fetch_x_props(&fi);
fetch_cpu_info(&fi); fetch_cpu_info(&fi);

View File

@ -1366,6 +1366,10 @@ int notcurses_palette_size(const notcurses* nc){
return nc->tcache.colors; return nc->tcache.colors;
} }
bool notcurses_cantruecolor(const notcurses* nc){
return nc->tcache.RGBflag;
}
// turn on any specified stylebits // turn on any specified stylebits
void ncplane_styles_on(ncplane* n, unsigned stylebits){ void ncplane_styles_on(ncplane* n, unsigned stylebits){
n->attrword |= (stylebits & NCSTYLE_MASK); n->attrword |= (stylebits & NCSTYLE_MASK);