mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
honor LINES/COLUMNS if TIOCGWINSZ fails #1826
This commit is contained in:
parent
81ee3a8d95
commit
6aee702291
@ -22,12 +22,6 @@
|
||||
|
||||
#define ESC "\x1b"
|
||||
|
||||
// there does not exist any true standard terminal size. with that said, we
|
||||
// need assume *something* for the case where we're not actually attached to
|
||||
// a terminal (mainly unit tests, but also daemon environments).
|
||||
static const int DEFAULT_ROWS = 24;
|
||||
static const int DEFAULT_COLS = 80;
|
||||
|
||||
void notcurses_version_components(int* major, int* minor, int* patch, int* tweak){
|
||||
*major = NOTCURSES_VERNUM_MAJOR;
|
||||
*minor = NOTCURSES_VERNUM_MINOR;
|
||||
@ -222,10 +216,10 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache,
|
||||
// if we're not a real tty, we presumably haven't changed geometry, return
|
||||
if(fd < 0){
|
||||
if(rows){
|
||||
*rows = DEFAULT_ROWS;
|
||||
*rows = tcache->default_rows;
|
||||
}
|
||||
if(cols){
|
||||
*cols = DEFAULT_COLS;
|
||||
*cols = tcache->default_cols;
|
||||
}
|
||||
if(tcache){
|
||||
tcache->cellpixy = 0;
|
||||
@ -1074,9 +1068,6 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
return NULL;
|
||||
}
|
||||
ret->ttyfd = get_tty_fd(ret->ttyfp);
|
||||
if(ret->ttyfd < 0){
|
||||
fprintf(stderr, "Defaulting to %dx%d (output is not to a terminal)\n", DEFAULT_ROWS, DEFAULT_COLS);
|
||||
}
|
||||
if(recursive_lock_init(&ret->pilelock)){
|
||||
fprintf(stderr, "Couldn't initialize pile mutex\n");
|
||||
free(ret);
|
||||
|
@ -6,6 +6,42 @@
|
||||
#include "internal.h"
|
||||
#include "input.h"
|
||||
|
||||
// there does not exist any true standard terminal size. with that said, we
|
||||
// need assume *something* for the case where we're not actually attached to
|
||||
// a terminal (mainly unit tests, but also daemon environments). in preference
|
||||
// to this, we use the geometries defined by (in order of precedence):
|
||||
//
|
||||
// * TIOGWINSZ ioctl(2)
|
||||
// * LINES/COLUMNS environment variables
|
||||
// * lines/cols terminfo variables
|
||||
//
|
||||
// this function sets up ti->default_rows and ti->default_cols
|
||||
static int
|
||||
get_default_dimension(const char* envvar, const char* tinfovar, int def){
|
||||
const char* env = getenv(envvar);
|
||||
int num;
|
||||
if(env){
|
||||
num = atoi(env);
|
||||
if(num > 0){
|
||||
return num;
|
||||
}
|
||||
}
|
||||
num = tigetnum(tinfovar);
|
||||
if(num > 0){
|
||||
return num;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
static void
|
||||
get_default_geometry(tinfo* ti){
|
||||
ti->default_rows = get_default_dimension("LINES", "lines", 24);
|
||||
ti->default_cols = get_default_dimension("COLUMNS", "cols", 80);
|
||||
loginfo("Default geometry: %d row%s, %d column%s\n",
|
||||
ti->default_rows, ti->default_rows != 1 ? "s" : "",
|
||||
ti->default_cols, ti->default_cols != 1 ? "s" : "");
|
||||
}
|
||||
|
||||
// we found Sixel support -- set up the API
|
||||
static inline void
|
||||
setup_sixel_bitmaps(tinfo* ti, int fd){
|
||||
@ -388,6 +424,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
get_default_geometry(ti);
|
||||
ti->caps.utf8 = utf8;
|
||||
// allow the "rgb" boolean terminfo capability, a COLORTERM environment
|
||||
// variable of either "truecolor" or "24bit", or unconditionally enable it
|
||||
|
@ -161,6 +161,9 @@ typedef struct tinfo {
|
||||
// furthermore interprets DECSDM in the reverse sense of most terminals
|
||||
// (though possibly in conformance with the actual VT340).
|
||||
bool sprixel_cursor_hack; // mlterm fixes
|
||||
|
||||
int default_rows; // LINES environment var / lines terminfo / 24
|
||||
int default_cols; // COLUMNS environment var / cols terminfo / 80
|
||||
} tinfo;
|
||||
|
||||
// retrieve the terminfo(5)-style escape 'e' from tdesc (NULL if undefined).
|
||||
|
Loading…
x
Reference in New Issue
Block a user