move call to termname() into interrogate_terminfo() #2023

pull/1978/head
nick black 3 years ago
parent 9fcbf00420
commit 305e8fceea
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1,6 +1,5 @@
#include "version.h"
#include "builddef.h"
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
#include <fcntl.h>
#include <errno.h>
#include <string.h>
@ -857,16 +856,14 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
}
// we don't need a controlling tty for everything we do; allow a failure here
ret->ctermfd = get_tty_fd(ret->ttyfp);
const char* shortname_term;
int termerr;
if(setupterm(termtype, ret->ctermfd, &termerr) != OK){
if(setupterm(termtype, ret->ctermfd, &termerr)){
fprintf(stderr, "Terminfo error %d (see terminfo(3ncurses))\n", termerr);
goto err;
}
shortname_term = termname();
int cursor_y = -1;
int cursor_x = -1;
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8,
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, utf8,
1, flags & NCDIRECT_OPTION_INHIBIT_CBREAK,
TERMINAL_UNKNOWN, &cursor_y, &cursor_x, NULL)){
goto err;

@ -1,7 +1,6 @@
#include "input.h"
#include "internal.h"
#include "notcurses/direct.h"
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
#include <term.h>
#include <ctype.h>
#include <signal.h>

@ -3,7 +3,6 @@
#include "version.h"
#include "egcpool.h"
#include "internal.h"
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
#include <zlib.h>
#include <time.h>
#include <term.h>
@ -16,6 +15,7 @@
#include <stdlib.h>
#include <unistr.h>
#include <locale.h>
#include <ncurses.h>
#include <uniwbrk.h>
#include <inttypes.h>
#include <notcurses/direct.h>
@ -1133,7 +1133,6 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
free(ret);
return NULL;
}
const char* shortname_term = termname(); // longname() is also available
ret->rstate.logendy = -1;
ret->rstate.logendx = -1;
ret->rstate.x = ret->rstate.y = -1;
@ -1143,7 +1142,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
&ret->rstate.logendy : &fakecursory;
int* cursorx = opts->flags & NCOPTION_PRESERVE_CURSOR ?
&ret->rstate.logendx : &fakecursorx;
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8,
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, utf8,
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0,
opts->flags & NCOPTION_NO_FONT_CHANGES,
cursory, cursorx, &ret->stats)){

@ -1,6 +1,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
#include <ncurses.h>
#ifdef __linux__
#include <sys/utsname.h>
#endif
@ -661,13 +661,14 @@ macos_early_matches(const char* termname){
// Device Attributes, allowing us to get a negative response if our queries
// aren't supported by the terminal. we fire it off early because we have a
// full round trip before getting the reply, which is likely to pace init.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
unsigned noaltscreen, unsigned nocbreak, unsigned nonewfonts,
int interrogate_terminfo(tinfo* ti, int fd, unsigned utf8, unsigned noaltscreen,
unsigned nocbreak, unsigned nonewfonts,
int* cursor_y, int* cursor_x, ncsharedstats* stats){
const char* tname = termname(); // longname() is also available
queried_terminals_e qterm = TERMINAL_UNKNOWN;
memset(ti, 0, sizeof(*ti));
#ifdef __APPLE__
qterm = macos_early_matches(termname);
qterm = macos_early_matches(tname);
#endif
ti->linux_fb_fd = -1;
ti->linux_fbuffer = MAP_FAILED;
@ -702,13 +703,15 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
// allow the "rgb" boolean terminfo capability, a COLORTERM environment
// variable of either "truecolor" or "24bit", or unconditionally enable it
// for several terminals known to always support 8bpc rgb setaf/setab.
int colors = tigetnum("colors");
if(colors <= 0){
ti->caps.colors = 1;
}else{
ti->caps.colors = colors;
if(ti->caps.colors == 0){
int colors = tigetnum("colors");
if(colors <= 0){
ti->caps.colors = 1;
}else{
ti->caps.colors = colors;
}
ti->caps.rgb = query_rgb(); // independent of colors
}
ti->caps.rgb = query_rgb(); // independent of colors
const struct strtdesc {
escape_e esc;
const char* tinfo;
@ -757,7 +760,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
fprintf(stderr, "Required terminfo capability 'cup' not defined\n");
goto err;
}
if(colors){
if(ti->caps.colors > 1){
const char* initc = get_escape(ti, ESCAPE_INITC);
if(initc){
ti->caps.can_change_colors = tigetflag("ccc") == 1;
@ -835,7 +838,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
}
}
bool invertsixel = false;
if(apply_term_heuristics(ti, termname, fd, qterm, &tablelen, &tableused,
if(apply_term_heuristics(ti, tname, fd, qterm, &tablelen, &tableused,
&invertsixel)){
ncinputlayer_stop(&ti->input);
goto err;

@ -219,7 +219,7 @@ term_supported_styles(const tinfo* ti){
// console, identified via ioctl(2)s), pass it as qterm; otherwise use
// TERMINAL_UNKNOWN. |stats| may be NULL; either way, it will be handed to the
// input layer so that its stats can be recorded.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
int interrogate_terminfo(tinfo* ti, int fd, unsigned utf8,
unsigned noaltscreen, unsigned nocbreak,
unsigned nonewfonts, int* cursor_y, int* cursor_x,
struct ncsharedstats* stats);

@ -24,6 +24,14 @@ int prepare_windows_terminal(tinfo* ti, size_t* tablelen, size_t* tableused){
{ ESCAPE_CIVIS, "\x1b[?25l", },
{ ESCAPE_CNORM, "\x1b[?25h", },
{ ESCAPE_U7, "\x1b[6n", },
{ ESCAPE_BOLD, "\x1b[1m", },
{ ESCAPE_SITM, "\x1b[3m", },
{ ESCAPE_RITM, "\x1b[23m", },
{ ESCAPE_SMUL, "\x1b[4m", },
{ ESCAPE_RMUL, "\x1b[24m", },
{ ESCAPE_SMULX, "\x1b[4:3m", },
{ ESCAPE_SMULNOX, "\x1b[4:0m", },
{ ESCAPE_SGR0, "\x1b[0m", },
{ ESCAPE_MAX, NULL, }
}, *w;
for(w = wterms ; w->tinfo; ++w){
@ -33,5 +41,7 @@ int prepare_windows_terminal(tinfo* ti, size_t* tablelen, size_t* tableused){
}
ti->caps.rgb = true;
ti->caps.colors = 256;
ti->caps.quadrants = true;
ti->caps.braille = true;
return 0;
}

@ -38,7 +38,7 @@ TEST_CASE("Fbuf") {
}
// fill the fbuf with one large write
SUBCASE("FbufPutsCover") {
SUBCASE("FbufPutsCoverSingle") {
fbuf f{};
CHECK(0 == fbuf_init(&f));
CHECK(0 < f.size);
@ -56,7 +56,7 @@ TEST_CASE("Fbuf") {
}
// fill the fbuf with random writes
SUBCASE("FbufPutsCover") {
SUBCASE("FbufPutsCoverRandom") {
fbuf f{};
CHECK(0 == fbuf_init(&f));
CHECK(0 < f.size);

@ -1,6 +1,5 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "main.h"
#include <term.h>
#include <fcntl.h>
#include <clocale>
#include <cstring>

@ -30,7 +30,7 @@ void DrawBoard() { // draw all fixed components of the game
scoreplane_->set_base("", 0, scorechan);
scoreplane_->set_bg_alpha(NCALPHA_TRANSPARENT);
scoreplane_->set_fg_rgb(0xd040d0);
scoreplane_->printf(0, 1, "%s", getpwuid(geteuid())->pw_name);
scoreplane_->printf(0, 1, "%s", *std::make_unique<char*>(notcurses_accountname()));
scoreplane_->set_fg_rgb(0x00d0a0);
UpdateScore();
nc_.render();

@ -1,7 +1,6 @@
#define NCPP_EXCEPTIONS_PLEASE
#include <mutex>
#include <array>
#include <pwd.h>
#include <atomic>
#include <thread>
#include <chrono>

Loading…
Cancel
Save