Notcurses 3.0.17
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
termdesc.c File Reference
#include <fcntl.h>
#include <unistd.h>
#include <curses.h>
#include "internal.h"
#include "windows.h"
#include "linux.h"
Include dependency graph for termdesc.c:

Go to the source code of this file.

Macros

#define TRIDEVATTR   "\x1b[=c"
 
#define PRIDEVATTR   "\x1b[c"
 
#define XTVERSION   "\x1b[>0q"
 
#define XTGETTCAP   "\x1bP+q544e;524742;687061\x1b\\"
 
#define SECDEVATTR   "\x1b[>c"
 
#define KITTYQUERY   "\x1b_Gi=1,a=q;\x1b\\"
 
#define KKBDSUPPORT   "\x1b[=27u"
 
#define KKBDQUERY   "\x1b[?u"
 
#define XTMODKEYS   "\x1b[>2;1m\x1b[>4;2m"
 
#define IDQUERIES
 
#define DEFBGQ   "\x1b]11;?\e\\"
 
#define DEFFGQ   "\x1b]10;?\e\\"
 
#define DSRCPR   "\x1b[6n"
 
#define SUMQUERY   "\x1b[?2026$p"
 
#define PIXELMOUSEQUERY   "\x1b[?1016$p"
 
#define CREGSXTSM   "\x1b[?2;1;0S"
 
#define GEOMXTSM   "\x1b[?1;1;0S"
 
#define GEOMPIXEL   "\x1b[14t"
 
#define GEOMCELL   "\x1b[18t"
 
#define DIRECTIVES
 
#define KKEYBOARD_PUSH   "\x1b[>u"
 
#define KKBDENTER   KKEYBOARD_PUSH KKBDSUPPORT
 
#define SMCUP   DECSET(SET_SMCUP)
 
#define RMCUP   DECRST(SET_SMCUP)
 
#define PQUERYBUFLEN   4096
 
#define ENVVAR   "TERM"
 

Functions

int grow_esc_table (tinfo *ti, const char *tstr, escape_e esc, size_t *tlen, size_t *tused)
 
void free_terminfo_cache (tinfo *ti)
 
int enter_alternate_screen (int fd, FILE *ttyfp, tinfo *ti, unsigned drain)
 
int leave_alternate_screen (int fd, FILE *fp, tinfo *ti, unsigned drain)
 
int interrogate_terminfo (tinfo *ti, FILE *out, unsigned utf8, unsigned noaltscreen, unsigned nocbreak, unsigned nonewfonts, int *cursor_y, int *cursor_x, ncsharedstats *stats, int lmargin, int tmargin, int rmargin, int bmargin, unsigned draininput)
 
char * termdesc_longterm (const tinfo *ti)
 
int locate_cursor (tinfo *ti, unsigned *cursor_y, unsigned *cursor_x)
 
int tiocgwinsz (int fd, struct winsize *ws)
 
int cbreak_mode (tinfo *ti)
 
int putenv_term (const char *tname)
 

Macro Definition Documentation

◆ CREGSXTSM

#define CREGSXTSM   "\x1b[?2;1;0S"

Definition at line 433 of file termdesc.c.

◆ DEFBGQ

#define DEFBGQ   "\x1b]11;?\e\\"

Definition at line 414 of file termdesc.c.

◆ DEFFGQ

#define DEFFGQ   "\x1b]10;?\e\\"

Definition at line 415 of file termdesc.c.

◆ DIRECTIVES

#define DIRECTIVES
Value:
DEFFGQ \
DEFBGQ \
KKBDQUERY \
SUMQUERY \
PIXELMOUSEQUERY \
"\x1b[?1;3;256S" /* try to set 256 cregs */ \
"\x1b[?1;3;1024S" /* try to set 1024 cregs */ \
KITTYQUERY \
CREGSXTSM \
GEOMXTSM \
GEOMPIXEL \
GEOMCELL \
PRIDEVATTR

Definition at line 446 of file termdesc.c.

◆ DSRCPR

#define DSRCPR   "\x1b[6n"

Definition at line 423 of file termdesc.c.

◆ ENVVAR

#define ENVVAR   "TERM"

Definition at line 1660 of file termdesc.c.

◆ GEOMCELL

#define GEOMCELL   "\x1b[18t"

Definition at line 442 of file termdesc.c.

◆ GEOMPIXEL

#define GEOMPIXEL   "\x1b[14t"

Definition at line 439 of file termdesc.c.

◆ GEOMXTSM

#define GEOMXTSM   "\x1b[?1;1;0S"

Definition at line 436 of file termdesc.c.

◆ IDQUERIES

#define IDQUERIES
Value:
TRIDEVATTR \
XTVERSION \
XTGETTCAP \
SECDEVATTR

Definition at line 405 of file termdesc.c.

◆ KITTYQUERY

#define KITTYQUERY   "\x1b_Gi=1,a=q;\x1b\\"

Definition at line 383 of file termdesc.c.

◆ KKBDENTER

#define KKBDENTER   KKEYBOARD_PUSH KKBDSUPPORT

Definition at line 465 of file termdesc.c.

◆ KKBDQUERY

#define KKBDQUERY   "\x1b[?u"

Definition at line 395 of file termdesc.c.

◆ KKBDSUPPORT

#define KKBDSUPPORT   "\x1b[=27u"

Definition at line 390 of file termdesc.c.

◆ KKEYBOARD_PUSH

#define KKEYBOARD_PUSH   "\x1b[>u"

Definition at line 461 of file termdesc.c.

◆ PIXELMOUSEQUERY

#define PIXELMOUSEQUERY   "\x1b[?1016$p"

Definition at line 430 of file termdesc.c.

◆ PQUERYBUFLEN

#define PQUERYBUFLEN   4096

◆ PRIDEVATTR

#define PRIDEVATTR   "\x1b[c"

Definition at line 351 of file termdesc.c.

◆ RMCUP

#define RMCUP   DECRST(SET_SMCUP)

Definition at line 473 of file termdesc.c.

◆ SECDEVATTR

#define SECDEVATTR   "\x1b[>c"

Definition at line 373 of file termdesc.c.

◆ SMCUP

#define SMCUP   DECSET(SET_SMCUP)

Definition at line 472 of file termdesc.c.

◆ SUMQUERY

#define SUMQUERY   "\x1b[?2026$p"

Definition at line 427 of file termdesc.c.

◆ TRIDEVATTR

#define TRIDEVATTR   "\x1b[=c"

Definition at line 336 of file termdesc.c.

◆ XTGETTCAP

#define XTGETTCAP   "\x1bP+q544e;524742;687061\x1b\\"

Definition at line 364 of file termdesc.c.

◆ XTMODKEYS

#define XTMODKEYS   "\x1b[>2;1m\x1b[>4;2m"

Definition at line 400 of file termdesc.c.

◆ XTVERSION

#define XTVERSION   "\x1b[>0q"

Definition at line 354 of file termdesc.c.

Function Documentation

◆ cbreak_mode()

int cbreak_mode ( tinfo ti)

Definition at line 1622 of file termdesc.c.

1622 {
1623#ifndef __MINGW32__
1624 int ttyfd = ti->ttyfd;
1625 if(ttyfd < 0){
1626 return 0;
1627 }
1628 // assume it's not a true terminal (e.g. we might be redirected to a file)
1629 struct termios modtermios;
1630 memcpy(&modtermios, ti->tpreserved, sizeof(modtermios));
1631 // see termios(3). disabling ECHO and ICANON means input will not be echoed
1632 // to the screen, input is made available without enter-based buffering, and
1633 // line editing is disabled. since we have not gone into raw mode, ctrl+c
1634 // etc. still have their typical effects. ICRNL maps return to 13 (Ctrl+M)
1635 // instead of 10 (Ctrl+J).
1636 modtermios.c_lflag &= (~ECHO & ~ICANON);
1637 modtermios.c_iflag &= ~ICRNL;
1638 if(tcsetattr(ttyfd, TCSANOW, &modtermios)){
1639 logerror("error disabling echo / canonical on %d (%s)", ttyfd, strerror(errno));
1640 return -1;
1641 }
1642#else
1643 // we don't yet have a way to take Cygwin/MSYS2 out of canonical mode FIXME.
1644 DWORD mode;
1645 if(!GetConsoleMode(ti->inhandle, &mode)){
1646 logerror("error acquiring input mode");
1647 return -1;
1648 }
1649 mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
1650 if(!SetConsoleMode(ti->inhandle, mode)){
1651 logerror("error setting input mode");
1652 return -1;
1653 }
1654#endif
1655 return 0;
1656}
#define logerror(fmt,...)
Definition logging.h:32
struct termios * tpreserved
Definition termdesc.h:179
int ttyfd
Definition termdesc.h:108
Here is the caller graph for this function:

◆ enter_alternate_screen()

int enter_alternate_screen ( int  fd,
FILE *  ttyfp,
tinfo ti,
unsigned  drain 
)

Definition at line 559 of file termdesc.c.

559 {
560 if(ti->in_alt_screen){
561 return 0;
562 }
563 const char* popcolors = get_escape(ti, ESCAPE_RESTORECOLORS);
564 if(popcolors){
565 if(term_emit(popcolors, ttyfp, true)){
566 return -1;
567 }
568 }
569 const char* smcup = get_escape(ti, ESCAPE_SMCUP);
570 if(smcup == NULL){
571 logerror("alternate screen is unavailable");
572 return -1;
573 }
574 if(!drain){
575 if(ti->kbdlevel){
576 if(tty_emit(KKEYBOARD_POP, fd)){
577 return -1;
578 }
579 }else{
580 if(tty_emit(XTMODKEYSUNDO, fd)){
581 return -1;
582 }
583 }
584 }
585 if(tty_emit(smcup, fd) < 0){
586 return -1;
587 }
588 if(!drain){
589 if(ti->kbdlevel){
590 if(tty_emit(KKBDENTER, fd)){
591 return -1;
592 }
593 }else{
594 if(tty_emit(XTMODKEYS, fd)){
595 return -1;
596 }
597 }
598 }
599 const char* pushcolors = get_escape(ti, ESCAPE_SAVECOLORS);
600 if(pushcolors){
601 if(term_emit(pushcolors, ttyfp, true)){
602 return -1;
603 }
604 }
605 ti->in_alt_screen = true;
606 return 0;
607}
unsigned kbdlevel
Definition termdesc.h:215
bool in_alt_screen
Definition termdesc.h:218
#define KKBDENTER
Definition termdesc.c:465
#define XTMODKEYS
Definition termdesc.c:400
return NULL
Definition termdesc.h:228
@ ESCAPE_RESTORECOLORS
Definition termdesc.h:87
@ ESCAPE_SMCUP
Definition termdesc.h:67
@ ESCAPE_SAVECOLORS
Definition termdesc.h:86
#define XTMODKEYSUNDO
Definition termdesc.h:27
#define KKEYBOARD_POP
Definition termdesc.h:22
Here is the caller graph for this function:

◆ free_terminfo_cache()

void free_terminfo_cache ( tinfo ti)

Definition at line 197 of file termdesc.c.

197 {
198 stop_inputlayer(ti);
199 loginfo("brought down input layer");
200 if(ti->pixel_cleanup){
201 ti->pixel_cleanup(ti);
202 }
203 free(ti->termversion);
204 free(ti->esctable);
205#ifdef __linux__
206 if(ti->linux_fb_fd >= 0){
207 close(ti->linux_fb_fd);
208 }
209 free(ti->linux_fb_dev);
210 if(ti->linux_fbuffer != MAP_FAILED){
211 munmap(ti->linux_fbuffer, ti->linux_fb_len);
212 }
213#endif
214 free(ti->tpreserved);
215 loginfo("destroyed terminfo cache");
216}
int stop_inputlayer(tinfo *ti)
Definition in.c:2655
#define loginfo(fmt,...)
Definition logging.h:42
void(* pixel_cleanup)(struct tinfo *)
Definition termdesc.h:157
char * esctable
Definition termdesc.h:109
char * termversion
Definition termdesc.h:176
Here is the call graph for this function:
Here is the caller graph for this function:

◆ grow_esc_table()

int grow_esc_table ( tinfo ti,
const char *  tstr,
escape_e  esc,
size_t *  tlen,
size_t *  tused 
)

Definition at line 14 of file termdesc.c.

15 {
16 // the actual table can grow past 64KB, but we can't start there, as
17 // we only have 16-bit indices.
18 if(*tused >= 65535){
19 fprintf(stderr, "Can't add escape %d to full table\n", esc);
20 return -1;
21 }
22 if(get_escape(ti, esc)){
23 fprintf(stderr, "Already defined escape %d (%s)\n",
24 esc, get_escape(ti, esc));
25 return -1;
26 }
27 size_t slen = strlen(tstr) + 1; // count the nul term
28 if(*tlen - *tused < slen){
29 // guaranteed to give us enough space to add tstr (and then some)
30 size_t newsize = *tlen + 4020 + slen; // don't pull two pages ideally
31 char* tmp = realloc(ti->esctable, newsize);
32 if(tmp == NULL){
33 return -1;
34 }
35 ti->esctable = tmp;
36 *tlen = newsize;
37 }
38 // we now are guaranteed sufficient space to copy tstr
39 memcpy(ti->esctable + *tused, tstr, slen);
40 ti->escindices[esc] = *tused + 1; // one-bias
41 *tused += slen;
42 return 0;
43}
uint16_t escindices[ESCAPE_MAX]
Definition termdesc.h:107
Here is the caller graph for this function:

◆ interrogate_terminfo()

int interrogate_terminfo ( tinfo ti,
FILE *  out,
unsigned  utf8,
unsigned  noaltscreen,
unsigned  nocbreak,
unsigned  nonewfonts,
int *  cursor_y,
int *  cursor_x,
ncsharedstats stats,
int  lmargin,
int  tmargin,
int  rmargin,
int  bmargin,
unsigned  draininput 
)

Definition at line 1317 of file termdesc.c.

1321 {
1322 // if a specified termtype was provided in the notcurses_options, it was
1323 // loaded into our environment at TERM.
1324 const char* termtype = getenv("TERM");
1325 int foolcursor_x, foolcursor_y;
1326 if(!cursor_x){
1327 cursor_x = &foolcursor_x;
1328 }
1329 if(!cursor_y){
1330 cursor_y = &foolcursor_y;
1331 }
1332 *cursor_x = *cursor_y = -1;
1333 ti->sixelengine = NULL;
1334 ti->bg_collides_default = 0xfe000000;
1335 ti->fg_default = 0xff000000;
1336 ti->kbdlevel = UINT_MAX; // see comment in tinfo definition
1337 ti->maxpaletteread = -1;
1338 ti->qterm = TERMINAL_UNKNOWN;
1339 // we don't need a controlling tty for everything we do; allow a failure here
1340 ti->ttyfd = get_tty_fd(out);
1341 ti->gpmfd = -1;
1342 size_t tablelen = 0;
1343 size_t tableused = 0;
1344 const char* tname = NULL;
1345#ifdef __APPLE__
1346 ti->qterm = macos_early_matches();
1347#elif defined(__MINGW32__)
1348 if(termtype){
1349 logwarn("termtype (%s) ignored on windows", termtype);
1350 }
1351 if(prepare_windows_terminal(ti, &tablelen, &tableused)){
1352 logpanic("failed opening Windows ConPTY");
1353 return -1;
1354 }
1355#else
1356 ti->qterm = unix_early_matches(termtype);
1357#if defined(__linux__)
1358 ti->linux_fb_fd = -1;
1359 ti->linux_fbuffer = MAP_FAILED;
1360 // we might or might not program quadrants into the console font
1361 if(is_linux_console(ti->ttyfd)){
1362 ti->qterm = TERMINAL_LINUX;
1363 }
1364#endif
1365#endif
1366 if(ti->ttyfd >= 0){
1367#ifndef __MINGW32__
1368 if((ti->tpreserved = calloc(1, sizeof(*ti->tpreserved))) == NULL){
1369 return -1;
1370 }
1371 if(tcgetattr(ti->ttyfd, ti->tpreserved)){
1372 logpanic("couldn't preserve terminal state for %d (%s)", ti->ttyfd, strerror(errno));
1373 free(ti->tpreserved);
1374 return -1;
1375 }
1376 // enter cbreak mode regardless of user preference until we've performed
1377 // terminal interrogation. at that point, we might restore original mode.
1378 if(cbreak_mode(ti)){
1379 free(ti->tpreserved);
1380 return -1;
1381 }
1382#endif
1383 // if we already know our terminal (e.g. on the linux console), there's no
1384 // need to send the identification queries. the controls are sufficient.
1385 bool minimal = (ti->qterm != TERMINAL_UNKNOWN);
1386 if(send_initial_queries(ti, minimal, noaltscreen, draininput)){
1387 goto err;
1388 }
1389 }
1390#ifndef __MINGW32__
1391 // windows doesn't really have a concept of terminfo. you might ssh into other
1392 // machines, but they'll use the terminfo installed thereon (putty, etc.).
1393 int termerr;
1394 if(setupterm(termtype, ti->ttyfd, &termerr)){
1395 logpanic("terminfo error %d for [%s] (see terminfo(3ncurses))",
1396 termerr, termtype ? termtype : "");
1397 goto err;
1398 }
1399 tname = termname(); // longname() is also available
1400 int linesigs_enabled = 1;
1401 if(ti->tpreserved){
1402 if(!(ti->tpreserved->c_lflag & ISIG)){
1403 linesigs_enabled = 0;
1404 }
1405 }
1406#else
1407 int linesigs_enabled = 0;
1408#endif
1409 if(init_inputlayer(ti, stdin, lmargin, tmargin, rmargin, bmargin,
1410 stats, draininput, linesigs_enabled)){
1411 goto err;
1412 }
1413 ti->sprixel_scale_height = 1;
1414 get_default_geometry(ti);
1415 ti->caps.utf8 = utf8;
1416 // allow the "rgb" boolean terminfo capability, a COLORTERM environment
1417 // variable of either "truecolor" or "24bit", or unconditionally enable it
1418 // for several terminals known to always support 8bpc rgb setaf/setab.
1419 if(ti->caps.colors == 0){
1420 int colors = tigetnum("colors");
1421 if(colors <= 0){
1422 ti->caps.colors = 1;
1423 }else{
1424 ti->caps.colors = colors;
1425 }
1426 ti->caps.rgb = query_rgb(); // independent of colors
1427 }
1428 if(do_terminfo_lookups(ti, &tablelen, &tableused)){
1429 goto err;
1430 }
1431 if(ti->ttyfd >= 0){
1432 // if the keypad needn't be explicitly enabled, smkx is not present
1433 const char* smkx = get_escape(ti, ESCAPE_SMKX);
1434 if(smkx){
1435 if(tty_emit(tiparm(smkx), ti->ttyfd) < 0){
1436 logpanic("error enabling keypad transmit mode");
1437 goto err;
1438 }
1439 }
1440 }
1441 if(tigetflag("bce") > 0){
1442 ti->bce = true;
1443 }
1444 if(ti->caps.colors > 1){
1445 const char* initc = get_escape(ti, ESCAPE_INITC);
1446 if(initc){
1447 ti->caps.can_change_colors = true;
1448 }
1449 }else{ // disable initc if there's no color support
1450 ti->escindices[ESCAPE_INITC] = 0;
1451 }
1452 // neither of these is supported on e.g. the "linux" virtual console.
1453 if(!noaltscreen){
1454 if(init_terminfo_esc(ti, "smcup", ESCAPE_SMCUP, &tablelen, &tableused) ||
1455 init_terminfo_esc(ti, "rmcup", ESCAPE_RMCUP, &tablelen, &tableused)){
1456 goto err;
1457 }
1458 const char* smcup = get_escape(ti, ESCAPE_SMCUP);
1459 if(smcup){
1460 ti->in_alt_screen = 1;
1461 // if we're not using the standard smcup, our initial hardcoded use of it
1462 // presumably had no effect; warn the user.
1463 if(strcmp(smcup, SMCUP)){
1464 logwarn("warning: non-standard smcup!");
1465 }
1466 }
1467 }else{
1468 ti->escindices[ESCAPE_SMCUP] = 0;
1469 ti->escindices[ESCAPE_RMCUP] = 0;
1470 }
1471 if(get_escape(ti, ESCAPE_CIVIS) == NULL){
1472 char* chts;
1473 if(terminfostr(&chts, "chts") == 0){
1474 if(grow_esc_table(ti, chts, ESCAPE_CIVIS, &tablelen, &tableused)){
1475 goto err;
1476 }
1477 }
1478 }
1479 if(get_escape(ti, ESCAPE_BOLD)){
1480 if(grow_esc_table(ti, "\e[22m", ESCAPE_NOBOLD, &tablelen, &tableused)){
1481 goto err;
1482 }
1483 }
1484 // if op is defined as ansi 39 + ansi 49, make the split definitions
1485 // available. this ought be asserted by extension capability "ax", but
1486 // no terminal i've found seems to do so. =[
1487 const char* op = get_escape(ti, ESCAPE_OP);
1488 if(op && strcmp(op, "\x1b[39;49m") == 0){
1489 if(grow_esc_table(ti, "\x1b[39m", ESCAPE_FGOP, &tablelen, &tableused) ||
1490 grow_esc_table(ti, "\x1b[49m", ESCAPE_BGOP, &tablelen, &tableused)){
1491 goto err;
1492 }
1493 }
1494 unsigned kitty_graphics = 0;
1495 if(ti->ttyfd >= 0){
1496 if(handle_responses(ti, &tablelen, &tableused, cursor_y, cursor_x,
1497 draininput, &kitty_graphics)){
1498 goto err;
1499 }
1500 if(nocbreak){
1501 // FIXME do this in input later, upon signaling completion?
1502 if(tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved)){
1503 goto err;
1504 }
1505 }
1506 }else{
1507 ti->kbdlevel = 0; // confirmed no support, don't bother popping
1508 }
1509 // now look up any terminfo elements we might not have received via requests
1510 if(ti->escindices[ESCAPE_HPA] == 0){
1511 if(init_terminfo_esc(ti, "hpa", ESCAPE_HPA, &tablelen, &tableused)){
1512 goto err;
1513 }
1514 }
1515 if(*cursor_x >= 0 && *cursor_y >= 0){
1516 if(add_u7_escape(ti, &tablelen, &tableused)){
1517 goto err;
1518 }
1519 }
1520 bool forcesdm = false;
1521 bool invertsixel = false;
1522 if(apply_term_heuristics(ti, tname, ti->qterm, &tablelen, &tableused,
1523 &forcesdm, &invertsixel, nonewfonts)){
1524 goto err;
1525 }
1526 build_supported_styles(ti);
1527 if(ti->pixel_draw == NULL && ti->pixel_draw_late == NULL){
1528 // color_registers was only assigned if kitty_graphics were unavailable
1529 if(ti->color_registers > 0){
1530 setup_sixel_bitmaps(ti, ti->ttyfd, forcesdm, invertsixel);
1531 }
1532 if(kitty_graphics){
1533 setup_kitty_bitmaps(ti, ti->ttyfd, NCPIXEL_KITTY_STATIC);
1534 }
1535 }
1536 return 0;
1537
1538err:
1539 if(ti->ttyfd >= 0){
1540 // if we haven't yet received a reply confirming lack of kitty keyboard
1541 // support, it'll be UINT_MAX, and we ought try to pop (in case we died
1542 // following the keyboard set, but before confirming support).
1543 if(ti->kbdlevel){
1544 tty_emit(KKEYBOARD_POP, ti->ttyfd);
1545 }
1546 tty_emit(RMCUP, ti->ttyfd);
1547 }
1548 if(ti->tpreserved){
1549 (void)tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved);
1550 free(ti->tpreserved);
1551 ti->tpreserved = NULL;
1552 }
1553 stop_inputlayer(ti);
1554 free(ti->esctable);
1555 free(ti->termversion);
1556 del_curterm(cur_term);
1557 close(ti->ttyfd);
1558 ti->ttyfd = -1;
1559 return -1;
1560}
int get_tty_fd(FILE *ttyfp)
Definition fd.c:455
int init_inputlayer(tinfo *ti, FILE *infp, int lmargin, int tmargin, int rmargin, int bmargin, ncsharedstats *stats, unsigned drain, int linesigs_enabled)
Definition in.c:2638
@ TERMINAL_LINUX
Definition in.h:35
@ TERMINAL_UNKNOWN
Definition in.h:32
bool is_linux_console(int fd)
#define logwarn(fmt,...)
Definition logging.h:37
#define logpanic(fmt,...)
Definition logging.h:22
@ NCPIXEL_KITTY_STATIC
Definition notcurses.h:1680
unsigned colors
Definition notcurses.h:1637
bool can_change_colors
Definition notcurses.h:1640
queried_terminals_e qterm
Definition termdesc.h:177
int maxpaletteread
Definition termdesc.h:192
void * sixelengine
Definition termdesc.h:174
bool bce
Definition termdesc.h:217
int gpmfd
Definition termdesc.h:194
uint32_t bg_collides_default
Definition termdesc.h:126
unsigned sprixel_scale_height
Definition termdesc.h:173
nccapabilities caps
Definition termdesc.h:110
uint32_t fg_default
Definition termdesc.h:129
int(* pixel_draw_late)(const struct tinfo *, sprixel *s, int yoff, int xoff)
Definition termdesc.h:148
int color_registers
Definition termdesc.h:163
int(* pixel_draw)(const struct tinfo *, const struct ncpile *p, sprixel *s, fbuf *f, int y, int x)
Definition termdesc.h:146
#define SMCUP
Definition termdesc.c:472
int grow_esc_table(tinfo *ti, const char *tstr, escape_e esc, size_t *tlen, size_t *tused)
Definition termdesc.c:14
int cbreak_mode(tinfo *ti)
Definition termdesc.c:1622
#define RMCUP
Definition termdesc.c:473
@ ESCAPE_CIVIS
Definition termdesc.h:53
@ ESCAPE_BOLD
Definition termdesc.h:61
@ ESCAPE_NOBOLD
Definition termdesc.h:62
@ ESCAPE_OP
Definition termdesc.h:49
@ ESCAPE_RMCUP
Definition termdesc.h:68
@ ESCAPE_SMKX
Definition termdesc.h:64
@ ESCAPE_FGOP
Definition termdesc.h:50
@ ESCAPE_INITC
Definition termdesc.h:80
@ ESCAPE_BGOP
Definition termdesc.h:51
@ ESCAPE_HPA
Definition termdesc.h:45
int prepare_windows_terminal(struct tinfo *ti, size_t *tablelen, size_t *tableused)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leave_alternate_screen()

int leave_alternate_screen ( int  fd,
FILE *  fp,
tinfo ti,
unsigned  drain 
)

Definition at line 611 of file termdesc.c.

611 {
612 if(!ti->in_alt_screen){
613 return 0;
614 }
615 const char* rmcup = get_escape(ti, ESCAPE_RMCUP);
616 if(rmcup == NULL){
617 logerror("can't leave alternate screen");
618 return -1;
619 }
620 if(!drain){
621 if(ti->kbdlevel){
622 if(tty_emit(KKEYBOARD_POP, fd)){
623 return -1;
624 }
625 }else{
626 if(tty_emit(XTMODKEYSUNDO, fd)){
627 return -1;
628 }
629 }
630 }
631 const char* popcolors = get_escape(ti, ESCAPE_RESTORECOLORS);
632 if(popcolors){
633 if(term_emit(popcolors, fp, true)){
634 return -1;
635 }
636 }
637 if(tty_emit(rmcup, fd)){
638 return -1;
639 }
640 if(!drain){
641 if(ti->kbdlevel){
642 if(tty_emit(KKBDENTER, fd)){
643 return -1;
644 }
645 }else{
646 if(tty_emit(XTMODKEYS, fd)){
647 return -1;
648 }
649 }
650 }
651 const char* pushcolors = get_escape(ti, ESCAPE_SAVECOLORS);
652 if(pushcolors){
653 if(term_emit(popcolors, fp, true)){
654 return -1;
655 }
656 }
657 ti->in_alt_screen = false;
658 return 0;
659}
Here is the caller graph for this function:

◆ locate_cursor()

int locate_cursor ( tinfo ti,
unsigned *  cursor_y,
unsigned *  cursor_x 
)

Definition at line 1585 of file termdesc.c.

1585 {
1586 const char* u7 = get_escape(ti, ESCAPE_U7);
1587 if(u7 == NULL){
1588 logwarn("no support in terminfo");
1589 return -1;
1590 }
1591 if(ti->ttyfd < 0){
1592 logwarn("no valid path for cursor report");
1593 return -1;
1594 }
1595 int fd = ti->ttyfd;
1596 if(get_cursor_location(ti->ictx, u7, cursor_y, cursor_x)){
1597 return -1;
1598 }
1599 loginfo("got a report from %d %d/%d", fd, *cursor_y, *cursor_x);
1600 return 0;
1601}
int get_cursor_location(inputctx *ictx, const char *u7, unsigned *y, unsigned *x)
Definition in.c:2810
struct inputctx * ictx
Definition termdesc.h:180
@ ESCAPE_U7
Definition termdesc.h:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ putenv_term()

int putenv_term ( const char *  tname)

Definition at line 1661 of file termdesc.c.

1661 {
1662 const char* oldterm = getenv(ENVVAR);
1663 if(oldterm){
1664 if(strcmp(oldterm, tname) == 0){
1665 return 0;
1666 }
1667 logdebug("replacing " ENVVAR " value %s with %s", oldterm, tname);
1668 }else{
1669 loginfo("providing " ENVVAR "=%s", tname);
1670 }
1671#ifndef __MINGW32__
1672 if(setenv(ENVVAR, tname, 1)){
1673#else
1674 SetEnvironmentVariable(ENVVAR, NULL); // clear it from environment
1675 if(!SetEnvironmentVariable(ENVVAR, tname)){ // set it
1676#endif
1677 logerror("error exporting " ENVVAR "=%s (%s)", tname, strerror(errno));
1678 return -1;
1679 }
1680 return 0;
1681}
#define logdebug(fmt,...)
Definition logging.h:52
#define ENVVAR
Definition termdesc.c:1660
Here is the caller graph for this function:

◆ termdesc_longterm()

char * termdesc_longterm ( const tinfo ti)

Definition at line 1562 of file termdesc.c.

1562 {
1563 size_t tlen = strlen(ti->termname) + 1;
1564 size_t slen = tlen;
1565 if(ti->termversion){
1566 slen += strlen(ti->termversion) + 1;
1567 }
1568 char* ret = malloc(slen);
1569 if(ret){
1570 memcpy(ret, ti->termname, tlen);
1571 if(ti->termversion){
1572 ret[tlen - 1] = ' ';
1573 strcpy(ret + tlen, ti->termversion);
1574 }
1575 }
1576 return ret;
1577}
const char * termname
Definition termdesc.h:175
Here is the caller graph for this function:

◆ tiocgwinsz()

int tiocgwinsz ( int  fd,
struct winsize *  ws 
)

Definition at line 1603 of file termdesc.c.

1603 {
1604#ifndef __MINGW32__
1605 int i = ioctl(fd, TIOCGWINSZ, ws);
1606 if(i < 0){
1607 logerror("TIOCGWINSZ failed on %d (%s)", fd, strerror(errno));
1608 return -1;
1609 }
1610 if(ws->ws_row <= 0 || ws->ws_col <= 0){
1611 logerror("bogon from TIOCGWINSZ on %d (%d/%d)",
1612 fd, ws->ws_row, ws->ws_col);
1613 return -1;
1614 }
1615#else
1616 (void)fd;
1617 (void)ws;
1618#endif
1619 return 0;
1620}
Here is the caller graph for this function: