get linux kernel version for termversion

pull/1813/head
nick black 3 years ago committed by Nick Black
parent 3d6a9b1c7a
commit 759de01d02

@ -824,7 +824,8 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
}
shortname_term = termname();
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8,
1, flags & NCDIRECT_OPTION_INHIBIT_CBREAK)){
1, flags & NCDIRECT_OPTION_INHIBIT_CBREAK,
TERMINAL_UNKNOWN)){
goto err;
}
if(ncvisual_init(NCLOGLEVEL_SILENT)){

@ -1156,6 +1156,7 @@ int ncinputlayer_init(tinfo* tcache, FILE* infp, queried_terminals_e* detected,
nilayer->inputbuf_valid_starts = 0;
nilayer->inputbuf_write_at = 0;
nilayer->input_events = 0;
if(*detected == TERMINAL_UNKNOWN){
int csifd = nilayer->ttyfd >= 0 ? nilayer->ttyfd : nilayer->infd;
if(isatty(csifd)){
query_state inits = {
@ -1173,5 +1174,6 @@ int ncinputlayer_init(tinfo* tcache, FILE* infp, queried_terminals_e* detected,
*detected = inits.qterm;
*appsync = inits.appsync;
}
}
return 0;
}

@ -1,3 +1,4 @@
#include "input.h"
#include "version.h"
#include "egcpool.h"
#include "internal.h"
@ -1054,7 +1055,10 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
return NULL;
}
ret->ttyfd = get_tty_fd(ret->ttyfp);
is_linux_console(ret, !!(opts->flags & NCOPTION_NO_FONT_CHANGES));
queried_terminals_e detected_term = TERMINAL_UNKNOWN;
if(is_linux_console(ret, !!(opts->flags & NCOPTION_NO_FONT_CHANGES))){
detected_term = TERMINAL_LINUX;
}
if(ret->ttyfd < 0){
fprintf(stderr, "Defaulting to %dx%d (output is not to a terminal)\n", DEFAULT_ROWS, DEFAULT_COLS);
}
@ -1091,7 +1095,8 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
const char* shortname_term = termname();
// const char* longname_term = longname();
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8,
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0)){
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0,
detected_term)){
goto err;
}
int dimy, dimx;

@ -1,5 +1,6 @@
#include <fcntl.h>
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
#include <sys/utsname.h>
#include "internal.h"
#include "input.h"
@ -242,8 +243,13 @@ apply_term_heuristics(tinfo* ti, const char* termname, int fd,
termname = "Contour";
ti->caps.quadrants = true;
ti->caps.rgb = true;
}else if(strcmp(termname, "linux") == 0){
}else if(qterm == TERMINAL_LINUX){
struct utsname un;
if(uname(&un) == 0){
ti->termversion = strdup(un.release);
}
termname = "Linux console";
// FIXME get kernel version
ti->caps.braille = false; // no caps.braille, no caps.sextants in linux console
// FIXME if the NCOPTION_NO_FONT_CHANGES, this isn't true
// FIXME we probably want to ID based off ioctl()s in linux.c
@ -304,13 +310,16 @@ send_initial_queries(int fd){
// 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 noaltscreen, unsigned nocbreak,
queried_terminals_e qterm){
memset(ti, 0, sizeof(*ti));
if(fd >= 0){
if(qterm == TERMINAL_UNKNOWN){
if(send_initial_queries(fd)){
fprintf(stderr, "Error issuing terminal queries on %d\n", fd);
return -1;
}
}
if(tcgetattr(fd, &ti->tpreserved)){
fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", fd, strerror(errno));
return -1;
@ -474,8 +483,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
}
}
unsigned appsync_advertised;
queried_terminals_e detected;
if(ncinputlayer_init(ti, stdin, &detected, &appsync_advertised)){
if(ncinputlayer_init(ti, stdin, &qterm, &appsync_advertised)){
goto err;
}
if(nocbreak){
@ -491,7 +499,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
goto err;
}
}
if(apply_term_heuristics(ti, termname, fd, detected, &tablelen, &tableused)){
if(apply_term_heuristics(ti, termname, fd, qterm, &tablelen, &tableused)){
ncinputlayer_stop(&ti->input);
goto err;
}

@ -7,6 +7,7 @@ extern "C" {
// internal header, not installed
#include "input.h"
#include <stdbool.h>
struct ncpile;
@ -177,8 +178,12 @@ term_supported_styles(const tinfo* ti){
// initialized. set |utf8| if we've verified UTF8 output encoding.
// set |noaltscreen| to inhibit alternate screen detection. |fd| ought
// be connected to a terminal device, or -1 if no terminal is available.
// if already *certain* of the terminal type (basically, if it's the Linux
// console, identified via ioctl(2)s), pass it as qterm; otherwise use
// TERMINAL_UNKNOWN.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
unsigned noaltscreen, unsigned nocbreak);
unsigned noaltscreen, unsigned nocbreak,
queried_terminals_e qterm);
void free_terminfo_cache(tinfo* ti);

Loading…
Cancel
Save