From 3c75654b6722360e41fc22a21aa423aa34b58867 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 25 Jun 2021 22:54:58 -0400 Subject: [PATCH] move is_linux_console to interrogate_term() so it's used in direct mode #1828 --- src/lib/internal.h | 2 +- src/lib/linux.c | 34 +++++++++++++++++----------------- src/lib/notcurses.c | 6 +----- src/lib/termdesc.c | 7 +++++-- src/lib/termdesc.h | 3 +-- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 19eaf6f84..f472f122f 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -1124,7 +1124,7 @@ int ncvisual_blit(struct ncvisual* ncv, int rows, int cols, void nclog(const char* fmt, ...); -bool is_linux_console(const notcurses* nc, unsigned no_font_changes); +bool is_linux_console(int fd, unsigned no_font_changes); // logging extern int loglevel; diff --git a/src/lib/linux.c b/src/lib/linux.c index e79111f7d..6ff2c977a 100644 --- a/src/lib/linux.c +++ b/src/lib/linux.c @@ -132,7 +132,7 @@ add_to_map(struct unimapdesc* map, wchar_t w, unsigned fidx){ } static int -program_line_drawing_chars(const notcurses* nc, struct unimapdesc* map){ +program_line_drawing_chars(int fd, struct unimapdesc* map){ struct simset { wchar_t* ws; } sets[] = { @@ -202,7 +202,7 @@ program_line_drawing_chars(const notcurses* nc, struct unimapdesc* map){ if(toadd == 0){ return 0; } - if(ioctl(nc->ttyfd, PIO_UNIMAP, map)){ + if(ioctl(fd, PIO_UNIMAP, map)){ logwarn("Error setting kernel unicode map (%s)\n", strerror(errno)); return -1; } @@ -212,7 +212,7 @@ program_line_drawing_chars(const notcurses* nc, struct unimapdesc* map){ } static int -program_block_drawing_chars(const notcurses* nc, struct console_font_op* cfo, +program_block_drawing_chars(int fd, struct console_font_op* cfo, struct unimapdesc* map){ struct shimmer { unsigned qbits; @@ -306,11 +306,11 @@ program_block_drawing_chars(const notcurses* nc, struct console_font_op* cfo, } } cfo->op = KD_FONT_OP_SET; - if(ioctl(nc->ttyfd, KDFONTOP, cfo)){ + if(ioctl(fd, KDFONTOP, cfo)){ logwarn("Error programming kernel font (%s)\n", strerror(errno)); return -1; } - if(ioctl(nc->ttyfd, PIO_UNIMAP, map)){ + if(ioctl(fd, PIO_UNIMAP, map)){ logwarn("Error setting kernel unicode map (%s)\n", strerror(errno)); return -1; } @@ -319,9 +319,9 @@ program_block_drawing_chars(const notcurses* nc, struct console_font_op* cfo, } static int -reprogram_linux_font(const notcurses* nc, struct console_font_op* cfo, +reprogram_linux_font(int fd, struct console_font_op* cfo, struct unimapdesc* map){ - if(ioctl(nc->ttyfd, KDFONTOP, cfo)){ + if(ioctl(fd, KDFONTOP, cfo)){ logwarn("Error reading Linux kernelfont (%s)\n", strerror(errno)); return -1; } @@ -331,24 +331,24 @@ reprogram_linux_font(const notcurses* nc, struct console_font_op* cfo, logwarn("Warning: kernel returned excess charcount\n"); return -1; } - if(ioctl(nc->ttyfd, GIO_UNIMAP, map)){ + if(ioctl(fd, GIO_UNIMAP, map)){ logwarn("Error reading Linux unimap (%s)\n", strerror(errno)); return -1; } loginfo("Kernel Unimap size: %hu/%hu\n", map->entry_ct, USHRT_MAX); // for certain sets of characters, we're not going to draw them in, but we // do want to ensure they map to something plausible... - if(program_line_drawing_chars(nc, map)){ + if(program_line_drawing_chars(fd, map)){ return -1; } - if(program_block_drawing_chars(nc, cfo, map)){ + if(program_block_drawing_chars(fd, cfo, map)){ return -1; } return 0; } static int -reprogram_console_font(const notcurses* nc){ +reprogram_console_font(int fd){ struct console_font_op cfo = { .op = KD_FONT_OP_GET, .charcount = 512, @@ -370,19 +370,19 @@ reprogram_console_font(const notcurses* nc){ free(cfo.data); return -1; } - int r = reprogram_linux_font(nc, &cfo, &map); + int r = reprogram_linux_font(fd, &cfo, &map); free(cfo.data); free(map.entries); return r; } // is the provided fd a Linux console? -bool is_linux_console(const notcurses* nc, unsigned no_font_changes){ - if(nc->ttyfd < 0){ +bool is_linux_console(int fd, unsigned no_font_changes){ + if(fd < 0){ return false; } int mode; - if(ioctl(nc->ttyfd, KDGETMODE, &mode)){ + if(ioctl(fd, KDGETMODE, &mode)){ logdebug("Not a Linux console, KDGETMODE failed\n"); return false; } @@ -391,11 +391,11 @@ bool is_linux_console(const notcurses* nc, unsigned no_font_changes){ logdebug("Not reprogramming the console font due to option\n"); return true; } - reprogram_console_font(nc); + reprogram_console_font(fd); return true; } #else -bool is_linux_console(const notcurses* nc, unsigned no_font_changes){ +bool is_linux_console(int fd, unsigned no_font_changes){ (void)nc; (void)no_font_changes; return false; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 5fff8092e..51fd2a5ee 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1074,10 +1074,6 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ return NULL; } ret->ttyfd = get_tty_fd(ret->ttyfp); - 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); } @@ -1116,7 +1112,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ int cursor_y = -1, cursor_x = -1; if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8, opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0, - detected_term, + opts->flags & NCOPTION_NO_FONT_CHANGES, opts->flags & NCOPTION_PRESERVE_CURSOR ? &cursor_y : NULL, opts->flags & NCOPTION_PRESERVE_CURSOR ? &cursor_x : NULL)){ goto err; diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 44b3f22a5..f9b11c527 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -336,10 +336,13 @@ apply_term_heuristics(tinfo* ti, const char* termname, 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, - queried_terminals_e qterm, + unsigned noaltscreen, unsigned nocbreak, unsigned nonewfonts, int* cursor_y, int* cursor_x){ + queried_terminals_e qterm = TERMINAL_UNKNOWN; memset(ti, 0, sizeof(*ti)); + if(is_linux_console(fd, nonewfonts)){ + qterm = TERMINAL_LINUX; + } if(fd >= 0){ if(qterm == TERMINAL_UNKNOWN){ if(send_initial_queries(fd)){ diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 1831eb3ab..65d922c6f 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -185,8 +185,7 @@ term_supported_styles(const tinfo* ti){ // TERMINAL_UNKNOWN. int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, unsigned noaltscreen, unsigned nocbreak, - queried_terminals_e qterm, - int* cursor_y, int* cursor_x); + unsigned nonewfonts, int* cursor_y, int* cursor_x); void free_terminfo_cache(tinfo* ti);