mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
add ncdirect_supported_styles(), move SGR/SGR0/OC into escblock #1525
This commit is contained in:
parent
91d8529f0f
commit
c4e2932c76
1
NEWS.md
1
NEWS.md
@ -7,6 +7,7 @@ rearrangements of Notcurses.
|
||||
* `ncinput_nomod_p()` has been added. This function returns `true` if and
|
||||
only if its `ncinput` argument has no modifiers active.
|
||||
* Added `notcurses_cursor_yx()` to get the current location of the cursor.
|
||||
* Added `ncdirect_supported_styles()`.
|
||||
|
||||
* 2.3.1 (2021-05-18)
|
||||
* Sprixels no longer interact with their associated plane's framebuffer. This
|
||||
|
@ -40,6 +40,8 @@ notcurses_direct - minimal notcurses instances for styling text
|
||||
|
||||
**int ncdirect_dim_y(const struct ncdirect* ***nc***);**
|
||||
|
||||
**unsigned ncdirect_supported_styles(const struct ncdirect* ***nc***);**
|
||||
|
||||
**int ncdirect_styles_set(struct ncdirect* ***n***, unsigned ***stylebits***);**
|
||||
|
||||
**int ncdirect_styles_on(struct ncdirect* ***n***, unsigned ***stylebits***);**
|
||||
|
@ -177,6 +177,12 @@ API int ncdirect_dim_x(const struct ncdirect* nc)
|
||||
API int ncdirect_dim_y(const struct ncdirect* nc)
|
||||
__attribute__ ((nonnull (1)));
|
||||
|
||||
// Returns a 16-bit bitmask of supported curses-style attributes
|
||||
// (NCSTYLE_UNDERLINE, NCSTYLE_BOLD, etc.) The attribute is only
|
||||
// indicated as supported if the terminal can support it together with color.
|
||||
// For more information, see the "ncv" capability in terminfo(5).
|
||||
API unsigned ncdirect_supported_styles(const struct ncdirect* nc);
|
||||
|
||||
// ncplane_styles_*() analogues
|
||||
API int ncdirect_set_styles(struct ncdirect* n, unsigned stylebits)
|
||||
__attribute__ ((nonnull (1)));
|
||||
|
@ -19,7 +19,8 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols,
|
||||
capyn(get_escape(ti, ESCAPE_SETAF)),
|
||||
capyn(get_escape(ti, ESCAPE_SETAB)));
|
||||
fprintf(debugfp, "%ssgr: %c sgr0: %c\n",
|
||||
indent, capyn(ti->sgr), capyn(ti->sgr0));
|
||||
indent, capyn(get_escape(ti, ESCAPE_SGR)),
|
||||
capyn(get_escape(ti, ESCAPE_SGR0)));
|
||||
fprintf(debugfp, "%sop: %c fgop: %c bgop: %c\n",
|
||||
indent, capyn(get_escape(ti, ESCAPE_OP)),
|
||||
capyn(get_escape(ti, ESCAPE_FGOP)),
|
||||
|
@ -812,10 +812,11 @@ char* ncdirect_readline(ncdirect* n, const char* prompt){
|
||||
static inline int
|
||||
ncdirect_style_emit(ncdirect* n, unsigned stylebits, FILE* out){
|
||||
int r = -1;
|
||||
if(stylebits == 0 && n->tcache.sgr0){
|
||||
r = term_emit(n->tcache.sgr0, n->ttyfp, false);
|
||||
}else if(n->tcache.sgr){
|
||||
r = term_emit(tiparm(n->tcache.sgr, stylebits & NCSTYLE_STANDOUT,
|
||||
const char* esc;
|
||||
if(stylebits == 0 && (esc = get_escape(&n->tcache, ESCAPE_SGR0))){
|
||||
r = term_emit(esc, n->ttyfp, false);
|
||||
}else if( (esc = get_escape(&n->tcache, ESCAPE_SGR)) ){
|
||||
r = term_emit(tiparm(esc, stylebits & NCSTYLE_STANDOUT,
|
||||
stylebits & NCSTYLE_UNDERLINE,
|
||||
stylebits & NCSTYLE_REVERSE,
|
||||
stylebits & NCSTYLE_BLINK,
|
||||
@ -1291,3 +1292,7 @@ int ncdirectf_geom(ncdirect* n, ncdirectf* frame,
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
unsigned ncdirect_supported_styles(const ncdirect* nc){
|
||||
return term_supported_styles(&nc->tcache);
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ int reset_term_attributes(const tinfo* ti, FILE* fp){
|
||||
if((esc = get_escape(ti, ESCAPE_OP)) && term_emit(esc, fp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
if(ti->sgr0 && term_emit(ti->sgr0, fp, true)){
|
||||
if((esc = get_escape(ti, ESCAPE_SGR0)) && term_emit(esc, fp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
if(ti->oc && term_emit(ti->oc, fp, true)){
|
||||
if((esc = get_escape(ti, ESCAPE_OC)) && term_emit(esc, fp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
@ -812,9 +812,10 @@ init_banner_warnings(const notcurses* nc, FILE* out){
|
||||
if(!get_escape(&nc->tcache, ESCAPE_HPA)){
|
||||
fprintf(out, "\n Warning! No absolute horizontal placement.\n");
|
||||
}
|
||||
if(nc->tcache.sgr0){
|
||||
const char* sgr0;
|
||||
if( (sgr0 = get_escape(&nc->tcache, ESCAPE_SGR0)) ){
|
||||
if(tty){
|
||||
term_emit(nc->tcache.sgr0, out, true);
|
||||
term_emit(sgr0, out, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -610,14 +610,16 @@ term_setstyles(FILE* out, notcurses* nc, const nccell* c){
|
||||
// target ought have all 0s in the lower 8 bits if only italics changed.
|
||||
if((cellattr ^ nc->rstate.curattr) & 0xfful){
|
||||
// if everything's 0, emit the shorter sgr0
|
||||
if(nc->tcache.sgr0 && ((cellattr & NCSTYLE_MASK) == 0)){
|
||||
if(term_emit(nc->tcache.sgr0, out, false) < 0){
|
||||
const char* sgr0 = get_escape(&nc->tcache, ESCAPE_SGR0);
|
||||
const char* sgr = get_escape(&nc->tcache, ESCAPE_SGR);
|
||||
if(sgr0 && ((cellattr & NCSTYLE_MASK) == 0)){
|
||||
if(term_emit(sgr0, out, false) < 0){
|
||||
ret = -1;
|
||||
}else{
|
||||
normalized = true;
|
||||
}
|
||||
}else if(nc->tcache.sgr){
|
||||
if(term_emit(tiparm(nc->tcache.sgr,
|
||||
}else if(sgr){
|
||||
if(term_emit(tiparm(sgr,
|
||||
cellattr & NCSTYLE_STANDOUT,
|
||||
cellattr & NCSTYLE_UNDERLINE,
|
||||
cellattr & NCSTYLE_REVERSE,
|
||||
|
@ -36,6 +36,7 @@ typedef enum {
|
||||
ESCAPE_SGR0, // "sgr0" turn off all styles
|
||||
ESCAPE_CIVIS, // "civis" make the cursor invisiable
|
||||
ESCAPE_CNORM, // "cnorm" restore the cursor to normal
|
||||
ESCAPE_OC, // "oc" restore original colors
|
||||
ESCAPE_MAX
|
||||
} escape_e;
|
||||
|
||||
@ -47,8 +48,6 @@ typedef enum {
|
||||
typedef struct tinfo {
|
||||
uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable
|
||||
char* esctable; // packed table of escape sequences
|
||||
char* sgr; // set many graphics properties at once
|
||||
char* sgr0; // restore default presentation properties
|
||||
unsigned colors;// number of colors terminfo reported usable for this screen
|
||||
char* cuu; // move N cells up
|
||||
char* cub; // move N cells left
|
||||
@ -66,7 +65,6 @@ typedef struct tinfo {
|
||||
char* struck; // NCSTYLE_STRUCK
|
||||
char* struckoff;// NCSTYLE_STRUCK (disable)
|
||||
char* initc; // set a palette entry's RGB value
|
||||
char* oc; // restore original colors
|
||||
char* clearscr; // erase screen and home cursor
|
||||
char* sc; // push the cursor location onto the stack
|
||||
char* rc; // pop the cursor location off the stack
|
||||
|
@ -204,6 +204,8 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
{ ESCAPE_OP, "op", },
|
||||
{ ESCAPE_CNORM, "cnorm", },
|
||||
{ ESCAPE_CIVIS, "civis", },
|
||||
{ ESCAPE_SGR, "sgr", },
|
||||
{ ESCAPE_SGR0, "sgr0", },
|
||||
{ ESCAPE_MAX, NULL, },
|
||||
};
|
||||
size_t tablelen = 0;
|
||||
@ -256,9 +258,6 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
}
|
||||
terminfostr(&ti->italics, "sitm"); // begin italic mode
|
||||
terminfostr(&ti->italoff, "ritm"); // end italic mode
|
||||
terminfostr(&ti->sgr, "sgr"); // define video attributes
|
||||
terminfostr(&ti->sgr0, "sgr0"); // turn off all video attributes
|
||||
terminfostr(&ti->oc, "oc"); // restore defaults to all colors
|
||||
terminfostr(&ti->home, "home"); // home the cursor
|
||||
terminfostr(&ti->clearscr, "clear");// clear screen, home cursor
|
||||
terminfostr(&ti->cuu, "cuu"); // move N up
|
||||
|
@ -8,14 +8,15 @@ TEST_CASE("DirectMode") {
|
||||
}
|
||||
|
||||
SUBCASE("SetItalic") {
|
||||
if(nc_->tcache.sgr){
|
||||
unsigned styles = ncdirect_supported_styles(nc_);
|
||||
if(styles & NCSTYLE_ITALIC){
|
||||
CHECK(0 == ncdirect_set_styles(nc_, NCSTYLE_ITALIC));
|
||||
}else{
|
||||
CHECK(0 != ncdirect_set_styles(nc_, NCSTYLE_ITALIC));
|
||||
}
|
||||
printf("DirectMode *italic*!\n");
|
||||
fflush(stdout);
|
||||
if(nc_->tcache.sgr0){
|
||||
if(styles & NCSTYLE_ITALIC){
|
||||
CHECK(0 == ncdirect_off_styles(nc_, NCSTYLE_ITALIC));
|
||||
}else{
|
||||
CHECK(0 != ncdirect_off_styles(nc_, NCSTYLE_ITALIC));
|
||||
@ -23,7 +24,8 @@ TEST_CASE("DirectMode") {
|
||||
}
|
||||
|
||||
SUBCASE("SetBold") {
|
||||
if(nc_->tcache.sgr){
|
||||
unsigned styles = ncdirect_supported_styles(nc_);
|
||||
if(styles & NCSTYLE_BOLD){
|
||||
CHECK(0 == ncdirect_set_styles(nc_, NCSTYLE_BOLD));
|
||||
printf("DirectMode *bold*!\n");
|
||||
fflush(stdout);
|
||||
@ -32,7 +34,8 @@ TEST_CASE("DirectMode") {
|
||||
}
|
||||
|
||||
SUBCASE("SetUnderline") {
|
||||
if(nc_->tcache.sgr){
|
||||
unsigned styles = ncdirect_supported_styles(nc_);
|
||||
if(styles & NCSTYLE_UNDERLINE){
|
||||
CHECK(0 == ncdirect_set_styles(nc_, NCSTYLE_UNDERLINE));
|
||||
printf("DirectMode *underline*!\n");
|
||||
fflush(stdout);
|
||||
@ -41,7 +44,8 @@ TEST_CASE("DirectMode") {
|
||||
}
|
||||
|
||||
SUBCASE("SetStruck") {
|
||||
if(nc_->tcache.sgr){
|
||||
unsigned styles = ncdirect_supported_styles(nc_);
|
||||
if(styles & NCSTYLE_STRUCK){
|
||||
CHECK(0 == ncdirect_set_styles(nc_, NCSTYLE_STRUCK));
|
||||
printf("DirectMode *struck*!\n");
|
||||
fflush(stdout);
|
||||
|
Loading…
x
Reference in New Issue
Block a user