From 0d7a5a5ef8e273029b5e99d46591f11a65d93812 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 13 Jun 2021 17:11:06 -0400 Subject: [PATCH] remove the majority of notcurses_check_pixel_support() calls #1469 --- NEWS.md | 9 +++++++++ README.md | 2 +- USAGE.md | 6 ++---- doc/man/man3/notcurses_capabilities.3.md | 3 +-- doc/man/man3/notcurses_plane.3.md | 5 +---- doc/man/man3/notcurses_visual.3.md | 8 -------- include/notcurses/direct.h | 4 +--- include/notcurses/notcurses.h | 10 +++------- src/fetch/main.c | 1 - src/info/main.c | 1 - src/lib/termdesc.c | 2 +- src/ls/main.cpp | 1 - 12 files changed, 19 insertions(+), 33 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7442b02c6..f6666b83b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,15 @@ This document attempts to list user-visible changes and any major internal rearrangements of Notcurses. * 2.3.5 (not yet released) + * Happy day! The terminal interrogation routines in the initialization code + have been completely revamped. The first outcome of this is that Sixel + parameters are now opportunistically read at startup, and thus there is + no longer any need to call `notcurses_check_pixel_support()` before + using `NCBLIT_PIXEL`. If it's there, it'll be used; if not, it'll degrade + or fail. Indeed, this function will likely be removed for ABI3. The new + routines rely on the terminal answering the Send Device Attributes escape; + if it does not, Notcurses may refuse to start, or even hang. Please report + a bug if you run into this. * `CELL_ALPHA_*` macros are now `NCALPHA_*`. The former will remain `#define`d until ABI3. diff --git a/README.md b/README.md index 6410f459d..002d19206 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ to breaking under incorrect `TERM` values. If you're not using `xterm`, your * **Q:** How about *arbitrary image manipulation here* functionality? **A:** I'm not going to beat ImageMagick et al. on image manipulation, but you can load an `ncvisual` from RGBA memory using `ncvisual_from_rgba()`. -* **Q:** My program locks up when I run `notcurses_check_pixel_support()`. **A**: Detecting bitmap support requires interrogating the terminal. If the terminal doesn't reply to standard interrogations, send upstream a patch, or use a different terminal. Generally, only old and unsupported terminal emulators exhibit this behavior. +* **Q:** My program locks up during initialization. **A**: Notcurses interrogates the terminal. If the terminal doesn't reply to standard interrogations, file a Notcurses bug, send upstream a patch, or use a different terminal. Generally, only old and unsupported terminal emulators exhibit this behavior. * **Q:** How do I mix Rendered and Direct mode? **A:** You really don't want to. You can stream a subprocess to a plane with the `ncsubproc` widget. diff --git a/USAGE.md b/USAGE.md index 8f39d227a..a3bf94d20 100644 --- a/USAGE.md +++ b/USAGE.md @@ -942,10 +942,8 @@ ncplane_dim_x(const struct ncplane* n){ // Retrieve pixel geometry for the display region ('pxy', 'pxx'), each cell // ('celldimy', 'celldimx'), and the maximum displayable bitmap ('maxbmapy', -// 'maxbmapx'). Note that this will call notcurses_check_pixel_support(), -// possibly leading to an interrogation of the terminal. If bitmaps are not -// supported, 'maxbmapy' and 'maxbmapx' will be 0. Any of the geometry -// arguments may be NULL. +// 'maxbmapx'). If bitmaps are not supported, 'maxbmapy' and 'maxbmapx' will +// be 0. Any of the geometry arguments may be NULL. void ncplane_pixelgeom(struct ncplane* n, int* restrict pxy, int* restrict pxx, int* restrict celldimy, int* restrict celldimx, int* restrict maxbmapy, int* restrict maxbmapx); diff --git a/doc/man/man3/notcurses_capabilities.3.md b/doc/man/man3/notcurses_capabilities.3.md index bbe841ee0..eba29bc36 100644 --- a/doc/man/man3/notcurses_capabilities.3.md +++ b/doc/man/man3/notcurses_capabilities.3.md @@ -87,8 +87,7 @@ quadrants and halfblocks, respectively. **notcurses_canbraille** returns these functions return **true** unless UTF-8 encoding is in use. **notcurses_check_pixel_support** returns 1 if bitmap support (via any -mechanism) is detected; **NCBLIT_PIXEL** can be used after such a return. -It returns 0 a lack of bitmap support was confirmed, and -1 on error. +mechanism) has been detected, and otherwise 0. # NOTES diff --git a/doc/man/man3/notcurses_plane.3.md b/doc/man/man3/notcurses_plane.3.md index 8dee4f0b2..f383946d9 100644 --- a/doc/man/man3/notcurses_plane.3.md +++ b/doc/man/man3/notcurses_plane.3.md @@ -363,10 +363,7 @@ plane when scrolling is enabled). return the size of the plane in pixels. **celldimy** and **celldimx** return the size of a cell in pixels (these ought be the same across planes). **maxbmapy** and **maxbmapx** describe the largest bitmap which can be -displayed in the plane. This function transitively calls -**notcurses_check_pixel_support**, possibly leading to terminal interrogation -(see **notcurses_capabilities(3)** for why this may be undesirable). Any -parameter (save **n**) may be **NULL**. +displayed in the plane. Any parameter (save **n**) may be **NULL**. When a plane is blitted to using **ncvisual_render** and **NCBLIT_PIXEL** (see **notcurses_visual(3)**), it ceases to accept cell-based output. The sprixel diff --git a/doc/man/man3/notcurses_visual.3.md b/doc/man/man3/notcurses_visual.3.md index 4a3dd72e3..067364a27 100644 --- a/doc/man/man3/notcurses_visual.3.md +++ b/doc/man/man3/notcurses_visual.3.md @@ -254,14 +254,6 @@ information. # PIXEL BLITTING Some terminals support pixel-based output via one of a number of protocols. -Checking for bitmap support requires interrogating the terminal and reading a -response. This takes time, and will never complete if the terminal doesn't -respond. Notcurses will not do so without an explicit request from the client -code. Before **NCBLIT_PIXEL** can be used, it is thus necessary to call -**notcurses_check_pixel_support**. If this function has not successfully -returned, attempts to use **NCBLIT_PIXEL** will fall back to cell-based -blitting (or fail, if **NCVISUAL_OPTION_NODEGRADE** is used). - **NCBLIT_PIXEL** has some stringent requirements on the type of planes it can be used with; it is usually best to let **ncvisual_render** create the backing plane by providing a **NULL** value for **n**. If you must bring your own diff --git a/include/notcurses/direct.h b/include/notcurses/direct.h index 717b3a11a..444278457 100644 --- a/include/notcurses/direct.h +++ b/include/notcurses/direct.h @@ -246,9 +246,7 @@ API bool ncdirect_canopen_images(const struct ncdirect* n) API bool ncdirect_canutf8(const struct ncdirect* n) __attribute__ ((nonnull (1))); -// This function must successfully return before NCBLIT_PIXEL is available. -// Returns -1 on error, 0 for no support, or 1 if pixel output is supported. -// Must not be called concurrently with either input or rasterization. +// Can we blit pixel-accurate bitmaps? API int ncdirect_check_pixel_support(struct ncdirect* n) __attribute__ ((nonnull (1))); diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 0161a2c7f..7d34f5564 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1122,10 +1122,8 @@ ncplane_dim_x(const struct ncplane* n){ // Retrieve pixel geometry for the display region ('pxy', 'pxx'), each cell // ('celldimy', 'celldimx'), and the maximum displayable bitmap ('maxbmapy', -// 'maxbmapx'). Note that this will call notcurses_check_pixel_support(), -// possibly leading to an interrogation of the terminal. If bitmaps are not -// supported, 'maxbmapy' and 'maxbmapx' will be 0. Any of the geometry -// arguments may be NULL. +// 'maxbmapx'). If bitmaps are not supported, 'maxbmapy' and 'maxbmapx' will +// be 0. Any of the geometry arguments may be NULL. API void ncplane_pixelgeom(struct ncplane* n, int* RESTRICT pxy, int* RESTRICT pxx, int* RESTRICT celldimy, int* RESTRICT celldimx, int* RESTRICT maxbmapy, int* RESTRICT maxbmapx) @@ -1292,9 +1290,7 @@ API bool notcurses_cansextant(const struct notcurses* nc) API bool notcurses_canbraille(const struct notcurses* nc) __attribute__ ((nonnull (1))); -// This function must successfully return before NCBLIT_PIXEL is available. -// Returns -1 on error, 0 for no support, or 1 if pixel output is supported. -// Must not be called concurrently with either input or rasterization. +// Can we blit pixel-accurate bitmaps? API int notcurses_check_pixel_support(struct notcurses* nc) __attribute__ ((nonnull (1))); diff --git a/src/fetch/main.c b/src/fetch/main.c index 99ba33e32..bcccb2dc9 100644 --- a/src/fetch/main.c +++ b/src/fetch/main.c @@ -578,7 +578,6 @@ display_thread(void* vmarshal){ struct marshal* m = vmarshal; drawpalette(m->nc); if(ncdirect_canopen_images(m->nc)){ - ncdirect_check_pixel_support(m->nc); if(m->logo){ if(ncdirect_render_image(m->nc, m->logo, NCALIGN_CENTER, NCBLIT_PIXEL, NCSCALE_SCALE_HIRES) == 0){ diff --git a/src/info/main.c b/src/info/main.c index fb7282268..c79a1b728 100644 --- a/src/info/main.c +++ b/src/info/main.c @@ -37,7 +37,6 @@ int main(void){ if(nc == NULL){ return EXIT_FAILURE; } - notcurses_check_pixel_support(nc); notcurses_debug_caps(nc, mstream); if(fclose(mstream)){ notcurses_stop(nc); diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 203dfbd01..9a4380e77 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -405,7 +405,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, if(ti->color_registers >= 64){ setup_sixel_bitmaps(ti); } - if(!nocbreak){ + if(nocbreak){ if(fd >= 0){ if(tcsetattr(fd, TCSANOW, &ti->tpreserved)){ ncinputlayer_stop(&ti->input); diff --git a/src/ls/main.cpp b/src/ls/main.cpp index 9c457e140..ca8d3a5e9 100644 --- a/src/ls/main.cpp +++ b/src/ls/main.cpp @@ -266,7 +266,6 @@ int main(int argc, char* const * argv){ blitter, scale, }; - ctx.nc.check_pixel_support(); keep_working = true; for(auto s = 0u ; s < procs ; ++s){ threads.emplace_back(std::thread(ncls_thread, &ctx));