mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
move smkx/rmkx smcup/rmcup into escape block #1525
This commit is contained in:
parent
c4e5ee2c38
commit
857d5e5958
@ -73,11 +73,12 @@ notcurses_stop_minimal(void* vnc){
|
||||
}
|
||||
ret |= reset_term_attributes(&nc->tcache, nc->ttyfp);
|
||||
ret |= notcurses_mouse_disable(nc);
|
||||
if(nc->tcache.rmcup && tty_emit(nc->tcache.rmcup, nc->ttyfd)){
|
||||
const char* esc;
|
||||
if((esc = get_escape(&nc->tcache, ESCAPE_RMCUP)) && tty_emit(esc, nc->ttyfd)){
|
||||
ret = -1;
|
||||
}
|
||||
if(nc->tcache.rmkx && tty_emit(nc->tcache.rmkx, nc->ttyfd)){
|
||||
ret = -1;
|
||||
if((esc = get_escape(&nc->tcache, ESCAPE_RMKX)) && tty_emit(esc, nc->ttyfd)){
|
||||
ret = -1;
|
||||
}
|
||||
const char* cnorm = get_escape(&nc->tcache, ESCAPE_CNORM);
|
||||
if(cnorm && tty_emit(cnorm, nc->ttyfd)){
|
||||
@ -1089,7 +1090,8 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if(ret->tcache.smkx && tty_emit(ret->tcache.smkx, ret->ttyfd)){
|
||||
const char* smkx = get_escape(&ret->tcache, ESCAPE_SMKX);
|
||||
if(smkx && tty_emit(smkx, ret->ttyfd)){
|
||||
free_plane(ret->stdplane);
|
||||
goto err;
|
||||
}
|
||||
@ -1107,8 +1109,9 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
init_banner(ret, shortname_term);
|
||||
// flush on the switch to alternate screen, lest initial output be swept away
|
||||
if(ret->ttyfd >= 0){
|
||||
if(ret->tcache.smcup){
|
||||
if(tty_emit(ret->tcache.smcup, ret->ttyfd)){
|
||||
const char* smcup = get_escape(&ret->tcache, ESCAPE_SMCUP);
|
||||
if(smcup){
|
||||
if(tty_emit(smcup, ret->ttyfd)){
|
||||
free_plane(ret->stdplane);
|
||||
goto err;
|
||||
}
|
||||
@ -1191,7 +1194,7 @@ int notcurses_stop(notcurses* nc){
|
||||
}
|
||||
// if we were not using the alternate screen, our cursor's wherever we last
|
||||
// wrote. move it to the bottom left of the screen.
|
||||
if(!nc->tcache.smcup){
|
||||
if(!get_escape(&nc->tcache, ESCAPE_SMCUP)){
|
||||
// if ldimy is 0, we've not yet written anything; leave it untouched
|
||||
if(nc->lfdimy){
|
||||
int targy = nc->lfdimy + nc->margin_t - 1;
|
||||
|
@ -164,6 +164,20 @@ grow_esc_table(tinfo* ti, const char* tstr, escape_e esc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
init_terminfo_esc(tinfo* ti, const char* name, escape_e idx,
|
||||
size_t* tablelen, size_t* tableused){
|
||||
char* tstr;
|
||||
if(terminfostr(&tstr, name) == 0){
|
||||
if(grow_esc_table(ti, tstr, idx, tablelen, tableused)){
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
ti->escindices[idx] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// termname is just the TERM environment variable. some details are not
|
||||
// exposed via terminfo, and we must make heuristic decisions based on
|
||||
// the detected terminal type, yuck :/.
|
||||
@ -213,18 +227,15 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
{ ESCAPE_CUF, "cuf", },
|
||||
{ ESCAPE_CUF1, "cuf1", },
|
||||
{ ESCAPE_CUB, "cub", },
|
||||
{ ESCAPE_SMKX, "smkx", },
|
||||
{ ESCAPE_RMKX, "rmkx", },
|
||||
{ ESCAPE_MAX, NULL, },
|
||||
};
|
||||
size_t tablelen = 0;
|
||||
size_t tableused = 0;
|
||||
for(typeof(*strtdescs)* strtdesc = strtdescs ; strtdesc->esc < ESCAPE_MAX ; ++strtdesc){
|
||||
char* tstr;
|
||||
if(terminfostr(&tstr, strtdesc->tinfo) == 0){
|
||||
if(grow_esc_table(ti, tstr, strtdesc->esc, &tablelen, &tableused)){
|
||||
goto err;
|
||||
}
|
||||
}else{
|
||||
ti->escindices[strtdesc->esc] = 0;
|
||||
if(init_terminfo_esc(ti, strtdesc->tinfo, strtdesc->esc, &tablelen, &tableused)){
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if(ti->escindices[ESCAPE_CUP] == 0){
|
||||
@ -233,8 +244,13 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
}
|
||||
// neither of these is supported on e.g. the "linux" virtual console.
|
||||
if(!noaltscreen){
|
||||
terminfostr(&ti->smcup, "smcup");
|
||||
terminfostr(&ti->rmcup, "rmcup");
|
||||
if(init_terminfo_esc(ti, "smcup", ESCAPE_SMCUP, &tablelen, &tableused) ||
|
||||
init_terminfo_esc(ti, "rmcup", ESCAPE_RMCUP, &tablelen, &tableused)){
|
||||
goto err;
|
||||
}
|
||||
}else{
|
||||
ti->escindices[ESCAPE_SMCUP] = 0;
|
||||
ti->escindices[ESCAPE_RMCUP] = 0;
|
||||
}
|
||||
// check that the terminal provides automatic margins
|
||||
ti->AMflag = tigetflag("am") == 1;
|
||||
@ -293,17 +309,14 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
ti->escindices[ESCAPE_RITM] = 0;
|
||||
}
|
||||
terminfostr(&ti->getm, "getm"); // get mouse events
|
||||
terminfostr(&ti->smkx, "smkx"); // enable keypad transmit
|
||||
terminfostr(&ti->rmkx, "rmkx"); // disable keypad transmit
|
||||
terminfostr(&ti->struck, "smxx"); // strikeout
|
||||
terminfostr(&ti->struckoff, "rmxx"); // cancel strikeout
|
||||
// if the keypad neen't be explicitly enabled, smkx is not present
|
||||
if(ti->smkx){
|
||||
if(fd >= 0){
|
||||
if(tty_emit(tiparm(ti->smkx), fd) < 0){
|
||||
fprintf(stderr, "Error entering keypad transmit mode\n");
|
||||
goto err;
|
||||
}
|
||||
const char* smkx = get_escape(ti, ESCAPE_SMKX);
|
||||
if(smkx && fd >= 0){
|
||||
if(tty_emit(tiparm(smkx), fd) < 0){
|
||||
fprintf(stderr, "Error entering keypad transmit mode\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// if op is defined as ansi 39 + ansi 49, make the split definitions
|
||||
|
@ -44,6 +44,10 @@ typedef enum {
|
||||
ESCAPE_CUF, // "cuf" move n cells forward (right)
|
||||
ESCAPE_CUD, // "cud" move n cells down
|
||||
ESCAPE_CUF1, // "cuf1" move 1 cell forward (right)
|
||||
ESCAPE_SMKX, // "smkx" keypad_xmit (keypad transmit mode)
|
||||
ESCAPE_RMKX, // "rmkx" keypad_local
|
||||
ESCAPE_SMCUP, // "smcup" enter alternate screen
|
||||
ESCAPE_RMCUP, // "rmcup" leave alternate screen
|
||||
ESCAPE_MAX
|
||||
} escape_e;
|
||||
|
||||
@ -63,16 +67,14 @@ typedef struct tinfo {
|
||||
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
|
||||
char* smkx; // enter keypad transmit mode (keypad_xmit)
|
||||
char* rmkx; // leave keypad transmit mode (keypad_local)
|
||||
char* getm; // get mouse events
|
||||
char* smcup; // enter alternate mode
|
||||
char* rmcup; // restore primary mode
|
||||
// we use the cell's size in pixels for pixel blitting. this information can
|
||||
// be acquired on all terminals with pixel support.
|
||||
int cellpixy; // cell pixel height, might be 0
|
||||
int cellpixx; // cell pixel width, might be 0
|
||||
|
||||
unsigned supported_styles; // bitmask over NCSTYLE_* driven via sgr/ncv
|
||||
|
||||
// kitty interprets an RGB background that matches the default background
|
||||
// color *as* the default background, meaning it'll be translucent if
|
||||
// background_opaque is in use. detect this, and avoid the default if so.
|
||||
@ -100,19 +102,11 @@ typedef struct tinfo {
|
||||
int (*pixel_clear_all)(int fd); // called during startup, kitty only
|
||||
int sprixel_scale_height; // sprixel must be a multiple of this many rows
|
||||
bool bitmap_supported; // do we support bitmaps (post pixel_query_done)?
|
||||
bool sprixel_cursor_hack; // do sprixels reset the cursor? (mlterm)
|
||||
bool pixel_query_done; // have we yet performed pixel query?
|
||||
// alacritty went rather off the reservation for their sixel support. they
|
||||
// reply to DSA with CSI?6c, meaning VT102, but no VT102 had Sixel support,
|
||||
// so if the TERM variable contains "alacritty", *and* we get VT102, we go
|
||||
// ahead and query XTSMGRAPHICS.
|
||||
bool alacritty_sixel_hack;
|
||||
|
||||
bool RGBflag; // "RGB" flag for 24bpc truecolor
|
||||
bool CCCflag; // "CCC" flag for palette set capability
|
||||
bool BCEflag; // "BCE" flag for erases with background color
|
||||
bool AMflag; // "AM" flag for automatic movement to next line
|
||||
unsigned supported_styles; // bitmask over NCSTYLE_* driven via sgr
|
||||
|
||||
// assigned based off nl_langinfo() in notcurses_core_init()
|
||||
bool utf8; // are we using utf-8 encoding, as hoped?
|
||||
@ -121,6 +115,16 @@ typedef struct tinfo {
|
||||
bool quadrants; // do we have (good, vetted) Unicode 1 quadrant support?
|
||||
bool sextants; // do we have (good, vetted) Unicode 13 sextant support?
|
||||
bool braille; // do we have Braille support? (linux console does not)
|
||||
|
||||
// alacritty went rather off the reservation for their sixel support. they
|
||||
// reply to DSA with CSI?6c, meaning VT102, but no VT102 had Sixel support,
|
||||
// so if the TERM variable contains "alacritty", *and* we get VT102, we go
|
||||
// ahead and query XTSMGRAPHICS.
|
||||
bool alacritty_sixel_hack;
|
||||
|
||||
// mlterm resets the cursor (i.e. makes it visible) any time you print
|
||||
// a sprixel. we work around this spiritedly unorthodox decision.
|
||||
bool sprixel_cursor_hack; // do sprixels reset the cursor? (mlterm)
|
||||
} tinfo;
|
||||
|
||||
// retrieve the terminfo(5)-style escape 'e' from tdesc (NULL if undefined).
|
||||
|
Loading…
x
Reference in New Issue
Block a user